text
stringlengths
27
54.3k
url
stringlengths
31
137
page_name
stringlengths
7
59
from fh_altair import altair2fasthml, altair_headers from fasthtml.common import * import numpy as np import pandas as pd import altair as alt app, rt = fast_app(hdrs=(altair_headers,)) count = 0 plotdata = [] def generate_chart(): global plotdata if len(plotdata) > 250: plotdata = plotdata[-250:] pltr = pd.DataFrame({...
https://gallery.fastht.ml/code/visualizations/altair_charts
FastHTML page
import plotly.express as px from fasthtml.common import * # Add the Plotly library to the headers app, rt = fast_app(hdrs=(Script(src="https://cdn.plot.ly/plotly-2.24.1.min.js"),)) def create_scatter_plot(): # Create simple scatter plot with 5 points fig = px.scatter( x=[1, 2, 3, 4, 5], y=[2, 4, 1, 3, 5], labels={"x": ...
https://gallery.fastht.ml/code/visualizations/plotly_selections
FastHTML page
Click the circle 3 times You have clicked 0 times
https://gallery.fastht.ml/app/svg/find_and_click/
FastHTML page
Click and drag an SVG rectangle with D3
https://gallery.fastht.ml/app/svg/click_and_drag/
FastHTML page
from fasthtml.common import * import numpy as np, seaborn as sns, matplotlib.pylab as plt app,rt = fast_app() data = np.random.rand(4,10) def fh_svg(func): "show svg in fasthtml decorator" def wrapper(*args, **kwargs): func(*args, **kwargs) # calls plotting function f = io.StringIO() # create a buffer to store svg data...
https://gallery.fastht.ml/split/visualizations/seaborn_svg
FastHTML page
from fh_altair import altair2fasthml, altair_headers from fasthtml.common import * import numpy as np import pandas as pd import altair as alt app, rt = fast_app(hdrs=(altair_headers,)) count = 0 plotdata = [] def generate_chart(): global plotdata if len(plotdata) > 250: plotdata = plotdata[-250:] pltr = pd.DataFrame({...
https://gallery.fastht.ml/split/visualizations/altair_charts
FastHTML page
Hello, world! I am a chatbot that can answer questions about the world. I have always wondered why the sky is blue. Can you tell me? The sky is blue because of the atmosphere. As white light passes through air molecules cause it to scatter. Because of the wavelengths, blue light is scattered the most.
https://gallery.fastht.ml/app/widgets/chat_bubble/
FastHTML page
from fasthtml.common import * from collections import deque app, rt = fast_app(exts='ws') # All messages here, but only most recent 15 are stored messages = deque(maxlen=15) users = {} # Takes all the messages and renders them box_style = "border: 1px solid #ccc; border-radius: 10px; padding: 10px; margin: 5px 0;" def ...
https://gallery.fastht.ml/split/dynamic_user_interface_(htmx)/web_sockets
FastHTML page
from fasthtml.common import * from collections import deque app, rt = fast_app(exts='ws') # All messages here, but only most recent 15 are stored messages = deque(maxlen=15) users = {} # Takes all the messages and renders them box_style = "border: 1px solid #ccc; border-radius: 10px; padding: 10px; margin: 5px 0;" def ...
https://gallery.fastht.ml/code/dynamic_user_interface_(htmx)/web_sockets
FastHTML page
from fasthtml.common import * app,rt = fast_app() def mk_row(name, email): return Tr(Td(name), Td(email)), @rt def index(): return Div(H2("Contacts"), Table( Thead(Tr(map(Th, ("Name", "Email")))), Tbody( mk_row("Audrey", "[email protected]"), mk_row("Uma" , "[email protected]"), mk_row("Daniel", "[email protected]")), ...
https://gallery.fastht.ml/code/dynamic_user_interface_(htmx)/update_other_content
FastHTML page
from fasthtml.common import * app, rt = fast_app() @rt def index(): return Titled('Try editing fields:', Grid(Div( Form(post="submit", hx_target="#result", hx_trigger="input delay:200ms")( Select(Option("One"), Option("Two"), id="select"), Input(value='j', id="name", placeholder="Name"), Input(value='h', id="email", pl...
https://gallery.fastht.ml/split/dynamic_user_interface_(htmx)/two_column_grid
FastHTML page
from fasthtml.common import * app,rt = fast_app() def mk_row(name, email): return Tr(Td(name), Td(email)), @rt def index(): return Div(H2("Contacts"), Table( Thead(Tr(map(Th, ("Name", "Email")))), Tbody( mk_row("Audrey", "[email protected]"), mk_row("Uma" , "[email protected]"), mk_row("Daniel", "[email protected]")), ...
https://gallery.fastht.ml/split/dynamic_user_interface_(htmx)/update_other_content
FastHTML page
from fasthtml.common import * app, rt = fast_app() @rt def index(): return Titled('Try editing fields:', Grid(Div( Form(post="submit", hx_target="#result", hx_trigger="input delay:200ms")( Select(Option("One"), Option("Two"), id="select"), Input(value='j', id="name", placeholder="Name"), Input(value='h', id="email", pl...
https://gallery.fastht.ml/code/dynamic_user_interface_(htmx)/two_column_grid
FastHTML page
from fasthtml.common import * app, rt = fast_app() content = """Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed sit amet volutpat tellus, in tincidunt magna. Vivamus congue posuere ligula a cursus. Sed efficitur tortor quis nisi mollis, eu aliquet nunc malesuada. Nulla semper lacus lacus, non sollicitudin ...
https://gallery.fastht.ml/split/dynamic_user_interface_(htmx)/show_hide
FastHTML page
from fasthtml.common import * app, rt = fast_app() content = """Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed sit amet volutpat tellus, in tincidunt magna. Vivamus congue posuere ligula a cursus. Sed efficitur tortor quis nisi mollis, eu aliquet nunc malesuada. Nulla semper lacus lacus, non sollicitudin ...
https://gallery.fastht.ml/code/dynamic_user_interface_(htmx)/show_hide
FastHTML page
from fasthtml.common import * import random app, rt = fast_app() def get_progress(percent_complete: int): "Simulate progress check" return percent_complete + random.random()/3 @rt def index(): return (Div(H3("Start the job to see progress!"),id='progress_bar'), Button("Start Job",post=update_status, hx_target="#progres...
https://gallery.fastht.ml/code/dynamic_user_interface_(htmx)/progress_bar
FastHTML page
Click any point to see its x-value!
https://gallery.fastht.ml/app/visualizations/plotly_selections/
Interactive Plotly Selection
from fasthtml.common import * import random app, rt = fast_app() def get_progress(percent_complete: int): "Simulate progress check" return percent_complete + random.random()/3 @rt def index(): return (Div(H3("Start the job to see progress!"),id='progress_bar'), Button("Start Job",post=update_status, hx_target="#progres...
https://gallery.fastht.ml/split/dynamic_user_interface_(htmx)/progress_bar
FastHTML page
from base64 import b64encode from fasthtml.common import * app, rt = fast_app() @rt def index(): inp = Card( H3("Drag and drop images here", style="text-align: center;"), # HTMX for uploading multiple images Input(type="file",name="images", multiple=True, required=True, # Call the upload route on change post=upload, hx...
https://gallery.fastht.ml/split/dynamic_user_interface_(htmx)/multi_image_upload
FastHTML page
from base64 import b64encode from fasthtml.common import * app, rt = fast_app() @rt def index(): inp = Card( H3("Drag and drop images here", style="text-align: center;"), # HTMX for uploading multiple images Input(type="file",name="images", multiple=True, required=True, # Call the upload route on change post=upload, hx...
https://gallery.fastht.ml/code/dynamic_user_interface_(htmx)/multi_image_upload
FastHTML page
from fasthtml.common import * from monsterui.all import * import asyncio app, rt = fast_app(hdrs=Theme.blue.headers()) @rt def index(): return Titled("Loading Demo", # Button to trigger an HTMX request Button("Load", id='load', # Trigger HTMX request to add content to #content get=load, hx_target='#content', hx_swap='b...
https://gallery.fastht.ml/code/dynamic_user_interface_(htmx)/loading_indicator
FastHTML page
Leave a message for others!
https://gallery.fastht.ml/app/dynamic_user_interface_(htmx)/web_sockets/
Leave a message for others!
from fasthtml.common import * import re ################ ### FastHTML ### ################ app, rt = fast_app() @rt def index(): return Form(post='submit', hx_target='#submit-btn-container', hx_swap='outerHTML')( # Calls /email route to validate email Div(hx_target='this', hx_swap='outerHTML')( Label(_for='email')('Ema...
https://gallery.fastht.ml/split/dynamic_user_interface_(htmx)/inline_validation
FastHTML page
from fasthtml.common import * import uuid column_names = ('name', 'email', 'id') def generate_contact(id: int) -> Dict[str, str]: return {'name': 'Agent Smith', 'email': f'void{str(id)}@matrix.com', 'id': str(uuid.uuid4()) } def generate_table_row(row_num: int) -> Tr: contact = generate_contact(row_num) return Tr(*[Td(...
https://gallery.fastht.ml/code/dynamic_user_interface_(htmx)/infinite_scroll
FastHTML page
from fasthtml.common import * import re ################ ### FastHTML ### ################ app, rt = fast_app() @rt def index(): return Form(post='submit', hx_target='#submit-btn-container', hx_swap='outerHTML')( # Calls /email route to validate email Div(hx_target='this', hx_swap='outerHTML')( Label(_for='email')('Ema...
https://gallery.fastht.ml/code/dynamic_user_interface_(htmx)/inline_validation
FastHTML page
from fasthtml.common import * from monsterui.all import * import asyncio app, rt = fast_app(hdrs=Theme.blue.headers()) @rt def index(): return Titled("Loading Demo", # Button to trigger an HTMX request Button("Load", id='load', # Trigger HTMX request to add content to #content get=load, hx_target='#content', hx_swap='b...
https://gallery.fastht.ml/split/dynamic_user_interface_(htmx)/loading_indicator
FastHTML page
from fasthtml.common import * import uuid column_names = ('name', 'email', 'id') def generate_contact(id: int) -> Dict[str, str]: return {'name': 'Agent Smith', 'email': f'void{str(id)}@matrix.com', 'id': str(uuid.uuid4()) } def generate_table_row(row_num: int) -> Tr: contact = generate_contact(row_num) return Tr(*[Td(...
https://gallery.fastht.ml/split/dynamic_user_interface_(htmx)/infinite_scroll
FastHTML page
from fasthtml.common import * app, rt = fast_app() # This represents the data we are rendering # The data could original from a database, or any other datastore @dataclass class Contact: # Data points id: int name: str email: str status: str def __ft__(self): # __ft__ method is used by FastHTML to render an item in the...
https://gallery.fastht.ml/code/dynamic_user_interface_(htmx)/delete_row
FastHTML page
from fasthtml.common import * app, rt = fast_app() # This represents the data we are rendering # The data could original from a database, or any other datastore @dataclass class Contact: # Data points id: int name: str email: str status: str def __ft__(self): # __ft__ method is used by FastHTML to render an item in the...
https://gallery.fastht.ml/split/dynamic_user_interface_(htmx)/delete_row
FastHTML page
Start the job to see progress!
https://gallery.fastht.ml/app/dynamic_user_interface_(htmx)/progress_bar/
FastHTML page
from fasthtml.common import * app, rt = fast_app() @rt def index():return Titled( "Custom Keybindings with HTMX", render_button("DO IT (Press `Shift + u`)")) @rt def doit(): return render_button("πŸ˜€ DID IT! ") def render_button(text): return Button(text, # Auto-focus on load autofocus=True, # Activate with click or U k...
https://gallery.fastht.ml/code/dynamic_user_interface_(htmx)/custom_keybindings
FastHTML page
from fasthtml.common import * app, rt = fast_app() @rt def index():return Titled( "Custom Keybindings with HTMX", render_button("DO IT (Press `Shift + u`)")) @rt def doit(): return render_button("πŸ˜€ DID IT! ") def render_button(text): return Button(text, # Auto-focus on load autofocus=True, # Activate with click or U k...
https://gallery.fastht.ml/split/dynamic_user_interface_(htmx)/custom_keybindings
FastHTML page
from fasthtml.common import * from monsterui.all import * app, rt = fast_app(hdrs=Theme.blue.headers()) @rt def index(): return Container(H1('Configurable Select'), mk_form()) @rt def mk_form(add_option:str=None, options:str='isaac,hamel,curtis'): opts = options.split(',') if add_option: opts.append(add_option) return ...
https://gallery.fastht.ml/split/dynamic_user_interface_(htmx)/configurable_select
FastHTML page
from uuid import uuid4 from fasthtml.common import * app, rt = fast_app() agent_num = 0 @rt def add_row(): global agent_num agent_num += 1 return Tr(map(Td, ( f"Agent Smith {agent_num}", f"smith{agent_num}@matrix.com", uuid4()))) @rt def index(): first_row = add_row() return Div( H1("Click to Load"), P("Dynamically add...
https://gallery.fastht.ml/code/dynamic_user_interface_(htmx)/click_to_load
FastHTML page
from uuid import uuid4 from fasthtml.common import * app, rt = fast_app() agent_num = 0 @rt def add_row(): global agent_num agent_num += 1 return Tr(map(Td, ( f"Agent Smith {agent_num}", f"smith{agent_num}@matrix.com", uuid4()))) @rt def index(): first_row = add_row() return Div( H1("Click to Load"), P("Dynamically add...
https://gallery.fastht.ml/split/dynamic_user_interface_(htmx)/click_to_load
FastHTML page
from fasthtml.common import * from monsterui.all import * app, rt = fast_app(hdrs=Theme.blue.headers()) @rt def index(): return Container(H1('Configurable Select'), mk_form()) @rt def mk_form(add_option:str=None, options:str='isaac,hamel,curtis'): opts = options.split(',') if add_option: opts.append(add_option) return ...
https://gallery.fastht.ml/code/dynamic_user_interface_(htmx)/configurable_select
FastHTML page
from fasthtml.common import * app, rt = fast_app() flds = dict(firstName='First Name', lastName='Last Name', email='Email') @dataclass class Contact: firstName:str; lastName:str; email:str; edit:bool=False def __ft__(self): def item(k, v): val = getattr(self,v) return Div(Label(Strong(k), val), Hidden(val, id=v)) retur...
https://gallery.fastht.ml/code/dynamic_user_interface_(htmx)/click_to_edit
FastHTML page
from fasthtml.common import * app, rt = fast_app() flds = dict(firstName='First Name', lastName='Last Name', email='Email') @dataclass class Contact: firstName:str; lastName:str; email:str; edit:bool=False def __ft__(self): def item(k, v): val = getattr(self,v) return Div(Label(Strong(k), val), Hidden(val, id=v)) retur...
https://gallery.fastht.ml/split/dynamic_user_interface_(htmx)/click_to_edit
FastHTML page
Email Address Is this cool?
https://gallery.fastht.ml/app/dynamic_user_interface_(htmx)/inline_validation/
FastHTML page
from fasthtml.common import * app, rt = fast_app() chapters = ['ch1', 'ch2', 'ch3'] lessons = { 'ch1': ['lesson1', 'lesson2', 'lesson3'], 'ch2': ['lesson4', 'lesson5', 'lesson6'], 'ch3': ['lesson7', 'lesson8', 'lesson9']} def mk_opts(nm, cs): return ( Option(f'-- select {nm} --', disabled='', selected='', value=''), *m...
https://gallery.fastht.ml/split/dynamic_user_interface_(htmx)/cascading_dropdowns
FastHTML page
from fasthtml.common import * from collections import defaultdict app, rt = fast_app() default_data = [ {'id': 1, 'name': 'Alice', 'age': 25}, {'id': 2, 'name': 'Bob', 'age': 30}, {'id': 3, 'name': 'Charlie', 'age': 28}, ] data = defaultdict(lambda: [dict(d) for d in default_data]) @rt def index(session): # if no id, c...
https://gallery.fastht.ml/split/dynamic_user_interface_(htmx)/bulk_update
FastHTML page
from fasthtml.common import * from collections import defaultdict app, rt = fast_app() default_data = [ {'id': 1, 'name': 'Alice', 'age': 25}, {'id': 2, 'name': 'Bob', 'age': 30}, {'id': 3, 'name': 'Charlie', 'age': 28}, ] data = defaultdict(lambda: [dict(d) for d in default_data]) @rt def index(session): # if no id, c...
https://gallery.fastht.ml/code/dynamic_user_interface_(htmx)/bulk_update
FastHTML page
Bulk Data Update with Fasthtml and HTMX This example demonstrates how to create a simple web application using Fasthtml and HTMX that allows users to bulk update data displayed in an HTML table. Users can modify the values in the table's input fields and then click a button to submit all the changes at once. Key Feat...
https://gallery.fastht.ml/info/dynamic_user_interface_(htmx)/bulk_update
FastHTML page
from fasthtml.common import * app, rt = fast_app() chapters = ['ch1', 'ch2', 'ch3'] lessons = { 'ch1': ['lesson1', 'lesson2', 'lesson3'], 'ch2': ['lesson4', 'lesson5', 'lesson6'], 'ch3': ['lesson7', 'lesson8', 'lesson9']} def mk_opts(nm, cs): return ( Option(f'-- select {nm} --', disabled='', selected='', value=''), *m...
https://gallery.fastht.ml/code/dynamic_user_interface_(htmx)/cascading_dropdowns
FastHTML page
import random from fasthtml.common import * app, rt = fast_app(hdrs=(Style(""" /* CSS to center content of the app */ body { max-width: 800px; padding: 20px; width: 90%; margin: 0 auto; } * { text-align: center; } /* CSS to fade in to full opacity in 1 second */ #fade-me-in.htmx-added { opacity: 0; } #fade-me-in { opac...
https://gallery.fastht.ml/code/dynamic_user_interface_(htmx)/animations
FastHTML page
Click to Load Dynamically add rows to a table using HTMX. Name Email ID Agent Smith 10 [email protected] ad464f20-3c84-4c42-a4a6-e775c65277dc
https://gallery.fastht.ml/app/dynamic_user_interface_(htmx)/click_to_load/
FastHTML page
import random from fasthtml.common import * app, rt = fast_app(hdrs=(Style(""" /* CSS to center content of the app */ body { max-width: 800px; padding: 20px; width: 90%; margin: 0 auto; } * { text-align: center; } /* CSS to fade in to full opacity in 1 second */ #fade-me-in.htmx-added { opacity: 0; } #fade-me-in { opac...
https://gallery.fastht.ml/split/dynamic_user_interface_(htmx)/animations
FastHTML page
A cascading dropdown component where values in second dropdown are dependent on the value in the first dropdown A searchable dropdown menu with a text box that allows user to add additional options to it via HTMX A table with infinite scroll over a large dataset (appending rows to the table as the user reaches the en...
https://gallery.fastht.ml/table
FastHTML page
Text Animations Color Throb Change text color every second in a smooth transition. Groovy baby, yeah! Settling Transitions Make a button disappear on click and gradually fade in.
https://gallery.fastht.ml/app/dynamic_user_interface_(htmx)/animations/
FastHTML page