I have used the instructions Access and Manipulate the URL — Panel v1.4.2 to change my app’s query parameters on the fly.
Now, I want to force the app to reload itself at that new URL.
I tried setting pn.state.location.reload=True – didn’t help
I have used the instructions Access and Manipulate the URL — Panel v1.4.2 to change my app’s query parameters on the fly.
Now, I want to force the app to reload itself at that new URL.
I tried setting pn.state.location.reload=True – didn’t help
As a hack, you can try setting reload=False
and then reload=True
.
import panel as pn
pn.extension()
def handle_click(event):
pn.state.location.param.update(search="?color=blue"),
pn.state.location.reload=False
pn.state.location.reload=True
print("handled")
pn.widgets.Button(name="Navigate to google", on_click=handle_click).servable()
It reloads the page for me. But I think that pn.state.location
does not work as you could expect as a user. Feel free to file an issue on Github.
Setting reload to False and then back to True did the trick – thanks for the tip!
Hello!
is it possible reload whole panel server, not only page?
im asking, because building multipage app with nested pages in nested folders and want to reload panel after changing some of pages
Do you mean restarting your panel server when you change the source code for it? During development you can do that with panel serve --autoreload
option.
I’d happy to, but after editing and saving one of pages, there is no auto restarting server
that’s how i starting application
panel serve .\app.py --static-dirs /assets=./static --autoreload
I’ve figured it out.
In the start file that launches the application, all modules for your project must be imported.
And also, if this suddenly does not help, you can do it manually using the button:
from pages import home, page1, page2
...
def reload_click(event):
for module_name in list(sys.modules.keys()):
if module_name.startswith('pages.'):
print(module_name)
importlib.reload(sys.modules[module_name])
# Reload the current page
current_page = pn.state.location.query_params.get('page')
pn.state.location.param.update(search=f"?page={current_page}")
pn.state.location.reload = False
pn.state.location.reload = True
reload_button = pn.widgets.Button(name='Reload', on_click=reload_click)
And modules, which are in folder page, reloading fine