Plot

Setup

hdrs = cond_pico_hdrs()+bootstrap_hdrs()+datatable_hdrs()+download_js()
show(*hdrs)
from ngrok_token import *
url = start_ngrok(token)
url
ngrok tunnel opened at: https://b4e9-3-81-185-19.ngrok-free.app
'https://b4e9-3-81-185-19.ngrok-free.app'
app,rt = fast_app(pico=False, live=True,hdrs=hdrs)
server = JupyUvi(app)

SVG Decorator


source

fh_svg

 fh_svg (func)

svg to fasthtml item

Use decorator to convert svg to fasthtml item

Heatmap


fh_svg..wrapper

 fh_svg.<locals>.wrapper (*args, **kwargs)
matrix = np.random.rand(20, 10)
df = pd.DataFrame(matrix)
plot_heatmap(df)
2024-11-05T01:25:18.555201 image/svg+xml Matplotlib v3.8.2, https://matplotlib.org/

Bar plot


fh_svg..wrapper

 fh_svg.<locals>.wrapper (*args, **kwargs)
matrix = np.random.rand(7, 2)
df = pd.DataFrame(matrix)

df.columns = ['ctrl','exp']
plot_bar(df,figsize=(4,2))
2024-11-05T01:25:20.983124 image/svg+xml Matplotlib v3.8.2, https://matplotlib.org/

Download plot


source

download_svg

 download_svg (*args, txt=' Plot', **kwargs)

The figure and download button has to bee placed within the same Div()

@rt
def test():
    return Div(download_svg(),Div(plot_bar(df,figsize=(4,2))))
htmx(url,'/test')

End

server.stop()
kill_ngrok()
ngrok tunnel killed