= Script("""
tooltip_js document.addEventListener('htmx:load', function() {
var tooltipTriggerList = document.querySelectorAll('[data-bs-toggle="tooltip"]');
var tooltipList = [...tooltipTriggerList].map(tooltipTriggerEl => new bootstrap.Tooltip(tooltipTriggerEl));
});
""")
Core
Setup
Headers
css, javascripts
Bootstrap
bootstrap_hdrs
bootstrap_hdrs (include_icon=True, include_tooltip=True)
Datatables for dynamic table
datatable_hdrs
datatable_hdrs ()
Conditional Pico
cond_pico_hdrs
cond_pico_hdrs ()
Copy TextArea js
copy_js
copy_js ()
Autocomplete js
autocomplete_js
autocomplete_js ()
Download csv/svg js
download_js
download_js ()
show() in cell magic
Fasthtml updates in the latest version that in jupyter notebook, no need to use show() when importing fasthtml.jupyter
s
s (line, cell)
Use %%s in a cell, so that you don’t have to wrap everything in show()
'sdf') P(
sdf
Jupyter live on colab
Initiate ngrok tunnel
get public url that connect to localhost:8000
start_ngrok
start_ngrok (token, port=8000)
kill_ngrok
kill_ngrok ()
Disconnect the specified ngrok url
Find ngrok token in https://dashboard.ngrok.com/get-started/your-authtoken
# ask users to type ngrok token
# from getpass import getpass
# token = getpass("Type your token: ")
# or directly import token variable
from ngrok_token import *
= start_ngrok(token) url
ngrok tunnel opened at: https://4a67-3-81-185-19.ngrok-free.app
Show Live page in jupyter cell
htmx
htmx (url, path='')
An iframe which displays the HTMX application in a notebook.
Example:
# url = start_ngrok(YOUR_NGROK_TOKEN)
= fast_app(live=True)
app,rt = JupyUvi(app) server
@rt
def index():
return Titled('Hello, Jupyter',
'Welcome to the FastHTML + Jupyter example'),
P('Click', hx_get='/click', hx_target='#dest'),
Button(id='dest')
Div(
)
@app.get
def click():
return P('Hi')
'/') # click `visit site` htmx(url,
push() in cell magic
p
p (line, cell)
Instead of wrapping everything in push, use %%p in a cell to do the same thing
# url = start_ngrok(YOUR_NGROK_TOKEN)
# app,rt = fast_app(exts='ws', live=True)
# server = JupyUvi(app) # JupyUvi is replaced with ws_client and setup_ws in the latest version
# push = Pusher(app)
# @app.get
# def click():
# return P('hi')
# %%p
# A('click',hx_get='/click',hx_target='#dest'),Div(id='dest')
# HTMX_public(url)
# server.stop()
server.stop() kill_ngrok()
ngrok tunnel killed