Can I pass query arguments to an app? #1853
-
I'm somewhat new to creating web apps, but is there a way to pass query arguments to a wave app? For example, if I had two apps, demo1 and demo2 (copied from examples/markdown_submit_text) demo1 with links to demo2from h2o_wave import main, app, Q, ui
def get_form_items(clicked: str):
return [
ui.text(content='Demo 1: The quick brown [fox](demo2?fox) jumps over the lazy [dog](demo2?dog)'),
ui.text(content=f'Clicked: {clicked}'),
]
@app('/demo1')
async def serve(q: Q):
if not q.client.initialized:
q.page['example'] = ui.form_card(box='1 1 3 2', items=get_form_items('Nothing'))
q.client.initialized = True
if q.args.fox:
q.page['example'].items = get_form_items('fox')
if q.args.dog:
q.page['example'].items = get_form_items('dog')
await q.page.save() demo2 with links to demo1from h2o_wave import main, app, Q, ui
def get_form_items(clicked: str):
return [
ui.text(content='Demo 2: The quick brown [fox](demo1?fox) jumps over the lazy [dog](demo1?dog)'),
ui.text(content=f'Clicked: {clicked}'),
]
@app('/demo2')
async def serve(q: Q):
if not q.client.initialized:
q.page['example'] = ui.form_card(box='1 1 3 2', items=get_form_items('Nothing'))
q.client.initialized = True
if q.args.fox:
q.page['example'].items = get_form_items('fox')
if q.args.dog:
q.page['example'].items = get_form_items('dog')
await q.page.save() If both of these apps are running, and I click "fox" on demo1, the demo2 app is displayed, but the 2nd line is Clicked: Nothing, while I would expect it to show that I clicked fox. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Sorry for late response @DeeJaayArgh, I must have overlooked your question.
I see where the confusion comes from. The catch is that This means your demo1 correctly redirects to demo2, but since Wave doesn't handle query arguments, they are ignored. However, adding support for initial load query arguments shouldn't be that hard so feel free to file a feature request. |
Beta Was this translation helpful? Give feedback.
Sorry for late response @DeeJaayArgh, I must have overlooked your question.
I see where the confusion comes from. The catch is that
?
is not a query argument, but rather a special kind of Wave syntax to allow values submission from markdown directly.This means your demo1 correctly redirects to demo2, but since Wave doesn't handle query arguments, they are ignored.
However, adding support for initial load query arguments shouldn't be that hard so feel free to file a feature request.