Skip to content

Instantly share code, notes, and snippets.

from h2o_wave import main, app, Q, ui
@app('/')
async def serve(q: Q):
# Check if a link is clicked or active in URL.
if q.args['#'] is not None:
# Set it to local state.
q.client.current_nav = f'#{q.args["#"]}'
from h2o_wave import main, app, Q, ui
@app('/')
async def serve(q: Q):
# Run this part only once, when the browser first connects.
if not q.client.initialized:
# Create a navigation card.
q.page['nav'] = ui.nav_card(
box='1 1 2 -1',
from h2o_wave import main, app, Q, ui
@app('/')
async def serve(q: Q):
if not q.client.initialized:
# Upload the file to the Wave server.
download_path, = await q.site.upload(['dataset.csv'])
q.client.initialized = True
from h2o_wave import main, app, Q, ui
@app('/')
async def serve(q: Q):
# Use app scope to make sure the file is uploaded only once.
if not q.app.initialized:
# Upload the file to the Wave server.
download_path, = await q.site.upload(['dataset.csv'])
q.app.initialized = True
const baseUrl = 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.33.0/min/vs'
// UNIMPORTANT: RequireJS paths config for monaco editor.
require.config({
paths: {
'vs': baseUrl,
'vs/language': `${baseUrl}/language`,
}
})
// UNIMPORTANT: Web worker registration for monaco editor.
window.MonacoEnvironment = {
from h2o_wave import main, app, Q, ui
# UNIMPORTANT: Helper function to read the file.
def read_file(p: str) -> str:
with open(p, encoding='utf-8') as f:
return f.read()
@app('/')
if q.events.editor:
if q.events.editor.save:
q.page['text'].content = q.events.editor.save
q.page['editor'].title = 'Editor'
elif q.events.editor.change:
# Show "dirty" state by appending an * to editor card title.
q.page['editor'].title = '*Editor'
from h2o_wave import main, app, Q, ui
# UNIMPORTANT: Helper function to read the file.
def read_file(p: str) -> str:
with open(p, encoding='utf-8') as f:
return f.read()
@app('/')
const baseUrl = 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.33.0/min/vs'
// UNIMPORTANT: RequireJS paths config for monaco editor.
require.config({
paths: {
'vs': baseUrl,
'vs/language': `${baseUrl}/language`,
}
})
// UNIMPORTANT: Web worker registration for monaco editor.
window.MonacoEnvironment = {
from h2o_wave import main, app, Q, ui
@app('/')
async def serve(q: Q):
# Initialize the page with a single button.
if not q.client.initialized:
q.page['form'] = ui.form_card(
box='1 1 2 1',
items=[
ui.button(name='start_recording', label='Start recording')