= bootstrap_hdrs()+download_js()+datatable_hdrs() hdrs
Form
Setup
*hdrs) show(
from ngrok_token import *
= start_ngrok(token) url
ngrok tunnel opened at: https://a223-3-238-95-91.ngrok-free.app
= fast_app(pico=False,hdrs=hdrs)
app,rt = JupyUvi(app) server
File upload & receive
Upload csv/excel file
get_file_input
get_file_input (label_text, id, **kwargs)
'Select csv/excel for upload',id='sdf') get_file_input(
Receive file
bytes2df
bytes2df (bytes_data, file_type)
Example
@rt
def file_upload(req):
= get_file_input(
add 'Upload your csv or excel',
id='myFile',post=preview, target_id='content',hx_trigger='change')
= A(Small('Download Example File'), href=req.url_for('download_example'),download='example.csv')
example_file
return Group(add,example_file), Div(id='content')
@app.get
def download_example():
return FileResponse('data/example.csv')
@app.post
async def preview(sess, myFile:UploadFile):
= myFile.filename
filename
if filename.endswith('.csv'):
= 'csv'
file_type elif filename.endswith(('.xls', '.xlsx')):
= 'excel'
file_type else:
return add_toast(sess, "Please upload a csv or excel file", "error")
# Data as byte string
= await myFile.read()
bytes_data = bytes2df(bytes_data,file_type)
df
if len(df)>100_000:
return add_toast(sess, "Exceed 100,000 lines, please use python api for large file", "warning")
return df2html(df.head())
'/file_upload') htmx(url,
Input text
get_input
get_input (label_text, id, cls=None, type='text', **kwargs)
'Gene ID',id='aa') get_input(
get_input_list
get_input_list (label_text, input_list, id, cls=None, type='text', **kwargs)
'Select item', ['a','b','c','d'],id='select') get_input_list(
TextArea
id='s', placeholder='sdf', cls='form-control',rows=10) Textarea(
Select (default is first)
get_select
get_select (label_text, option_list, id, cls=None, **kwargs)
The first item in the option_list is the default
Select
get_select_simple
get_select_simple (label_text, select_list, id, cls=None)
'select one', ['a','b','c'],id='ssdf') get_select_simple(
Select multiple
get_select_simple_multiple
get_select_simple_multiple (label_text, select_list, id, cls=None)
'select one', ['a','b','c'],id='ssss') get_select_simple_multiple(
Spinner
get_spinner
get_spinner (id, cls='d-flex justify-content-center')
id='sdf') get_spinner(
Loading...
Example:
# @app.post
# def example():
# ...
# send_select = Form(
# Hidden(value=df.to_json(),id='upload_df'),
# Div(select_list,button,cls='row g-2 align-items-center'),
# post=calculate,
# target_id='result',
# hx_indicator='#spinner',
# )
# spinner=get_spinner(id='spinner')
# return send_select, spinner, ...
End
server.stop() kill_ngrok()
ngrok tunnel killed