Open MarcSkovMadsen opened 1 month ago
I see the same problem when using pn.state.session_args
import panel as pn
from fastapi import FastAPI
from panel.io.fastapi import add_application
app = FastAPI()
@app.get("/")
async def read_root():
return {"Hello": "World"}
@add_application("/panel", app=app, title="My Panel App")
def create_panel_app():
slider = pn.widgets.IntSlider(name="Slider", start=0, end=10, value=3)
return pn.Column(
pn.state.location.query_params,
pn.state.session_args,
slider.rx() * "⭐",
)
According to https://fastapi.tiangolo.com/tutorial/query-params/ the query-params should be additional keywords not in the path. But that does not work either
import panel as pn
from fastapi import FastAPI
from panel.io.fastapi import add_application
app = FastAPI()
@app.get("/")
async def read_root():
return {"Hello": "World"}
@add_application("/panel", app=app, title="My Panel App")
def create_panel_app(hello: str=""):
print(hello)
slider = pn.widgets.IntSlider(name="Slider", start=0, end=10, value=3)
return pn.Column(
pn.pane.Str(hello, styles={"border": "1px solid black"}),
slider.rx() * "⭐",
)
This issue has been mentioned on HoloViz Discourse. There might be relevant details there:
https://discourse.holoviz.org/t/how-to-access-query-params-when-running-panel-using-fastapi/8240/2
You can sync widget/parameter values to the url though
import panel as pn
from fastapi import FastAPI
from panel.io.fastapi import add_application
app = FastAPI()
@app.get("/")
async def read_root():
return {"Hello": "World"}
@add_application("/panel", app=app, title="My Panel App")
def create_panel_app():
widget = pn.widgets.FloatSlider(name='Slider', start=0, end=10)
widget2 = pn.widgets.TextInput(name='Text')
widget3 = pn.widgets.RangeSlider(name='RangeSlider', start=0, end=10)
if pn.state.location:
pn.state.location.sync(widget, {'value': 'slider_value'})
pn.state.location.sync(widget2, {'value': 'text_value'})
pn.state.location.sync(widget3, {'value': 'range_value'})
return pn.Column(widget, widget2, widget3)
panel==1.5.1, bokeh-fastapi==0.1.0
No pn.state.location.query_params
In https://discourse.holoviz.org/t/how-to-access-query-params-when-running-panel-using-fastapi/8240 Makalai reports that
pn.state.location.query_params
is always empty when following https://panel.holoviz.org/how_to/integrations/FastAPI.html.I can reproduce this via