Created
September 18, 2023 15:35
-
-
Save simonw/b845c9bc2d2e6c07a13742b5cc5b5a7d to your computer and use it in GitHub Desktop.
Showing data from Datasette in Flet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Couldn't figure out how to do horizontal scrolling.