Skip to content

Instantly share code, notes, and snippets.

@simonw
Created September 18, 2023 15:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simonw/b845c9bc2d2e6c07a13742b5cc5b5a7d to your computer and use it in GitHub Desktop.
Save simonw/b845c9bc2d2e6c07a13742b5cc5b5a7d to your computer and use it in GitHub Desktop.
Showing data from Datasette in Flet
# pip install flet httpx
import flet as ft
import httpx
def main(page: ft.Page):
rows = httpx.get("https://simon.datasette.cloud/data/hacker_news_posts.json?_sort_desc=dt").json()["rows"]
first_row = rows[0]
page.scroll = ft.ScrollMode.ALWAYS
page.add(
ft.DataTable(
columns=[
ft.DataColumn(ft.Text(key), numeric=isinstance(value, int)) for key, value in first_row.items()
],
rows=[
ft.DataRow(
cells=[
ft.DataCell(ft.Text(str(value))) for value in row.values()
],
) for row in rows
],
),
)
ft.app(target=main)
@simonw
Copy link
Author

simonw commented Sep 18, 2023

CleanShot 2023-09-18 at 08 35 53@2x

Couldn't figure out how to do horizontal scrolling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment