Skip to content

Commit de8e53d

Browse files
committed
Minimal styling and make code lines less long so easier in split view
1 parent 8b8163e commit de8e53d

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

examples/visualizations/observable_plot/app.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from fasthtml.common import *
22
import numpy as np
3-
from starlette.responses import JSONResponse
43

54
plot_js = """
65
function createPlot(data) {
@@ -20,28 +19,24 @@
2019
"""
2120

2221
app, rt = fast_app(
23-
pico=False,
24-
hdrs=(
25-
Script(src="https://cdn.jsdelivr.net/npm/d3@7"),
26-
Script(src="https://cdn.jsdelivr.net/npm/@observablehq/[email protected]"),
27-
Script(src="https://unpkg.com/@tailwindcss/browser@4")
28-
)
29-
)
22+
hdrs=(Script(src="https://cdn.jsdelivr.net/npm/d3@7"),
23+
Script(src="https://cdn.jsdelivr.net/npm/@observablehq/[email protected]")))
3024

3125
@rt
3226
def index():
3327
return Div(
34-
H1("Observable Plot Demo", cls="text-4xl font-bold"),
35-
P("This FastHTML example renders an ", A("Observable Plot", href="https://observablehq.com/@observablehq/plot", target="_blank", cls="visited:text-purple-600 underline"), " chart. The data is randomly generated on the server and is fetched on initial page load. You can also click the button to fetch new random data from the server. Try opening the browser developer tools and viewing the Network tab to see the data reponse for each http request.", cls="my-4"),
36-
Button("Refresh Data", hx_get="get_data", hx_target="#data-store", cls="cursor-pointer rounded-md bg-slate-600 px-3.5 py-2.5 my-2 text-sm font-semibold text-white shadow-xs hover:bg-slate-500 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-slate-600"),
28+
H1(A("Observable", href="https://observablehq.com/@observablehq/plot", target="_blank"), " Plot Demo"),
29+
P("The data is randomly generated on the server and is fetched on initial page load."),
30+
P("Try opening the browser developer tools and viewing the Network tab to see the data reponse for each http request."),
31+
# On bytton click it sends a get request to the `get_data` route and puts the response in the `data-store` div
32+
Button("Fetch New Data", get=get_data, hx_target="#data-store", cls='btn btn-primary'),
3733
# Store for the JSON chart data
38-
Div(id="data-store", hx_get="get_data", hx_trigger="load", cls="hidden"),
34+
Div(id="data-store", get=get_data, hx_trigger="load", hidden=True),
3935
# Plot container
40-
Div(id="plot", cls="mt-12"),
36+
Div(id="plot"),
4137
# Include the JavaScript for the plot
42-
Script(plot_js),
43-
cls="m-12"
44-
)
38+
Script(plot_js)
39+
)
4540

4641
@rt
4742
def get_data():
File renamed without changes.

0 commit comments

Comments
 (0)