Hi, I have several multi-tab apps in Bokeh, with the last few lines similar to those shown below. I want to use the loading indicator, but can’t get it to show.
It would seem I am making a simple error, so apologies for the basic question.
Thanks. It seems I misunderstood. I was looking for a loading icon that shows while the app is being loaded. The apps I am currently using just show a white screen until the charts appear.
import panel as pn
import time
import holoviews as hv
pn.extension(sizing_mode="stretch_width")
loading_message = pn.pane.Markdown("The app is loading ...")
loading_indicator = pn.indicators.Progress(value=20, type="primary")
plot = pn.pane.HoloViews(sizing_mode="stretch_both", loading=True)
layout = pn.Column(
loading_message, loading_indicator, plot
)
def load():
for _ in range(0,3):
time.sleep(1)
loading_indicator.value+=20
data=pd.DataFrame({"x": [1,2], "y": [3,4]})
plot.sizing_mode="stretch_both"
plot.object = data.hvplot()
loading_message.visible=False
loading_indicator.visible=False
pn.state.onload(load)
layout.servable()
Another more reactive way could look like
import hvplot.pandas
import pandas as pd
import panel as pn
import time
import param
pn.extension(sizing_mode="stretch_width")
class StateBase(param.Parameterized):
"""General State Management Class. Inherit from this"""
value = param.Parameter()
def __init__(self, **params):
super().__init__(**params)
self.value = self
for parameter in self.param:
self.param[parameter].constant=True
def update(self, **kwargs):
"""Use this method only to update the state parameters"""
with param.edit_constant(self):
self.param.update(**kwargs)
self.param.trigger("value")
class AppState(StateBase):
progress = param.Integer()
data = param.Parameter()
state = AppState()
def component(state):
if state.data is None:
loading_message = pn.pane.Markdown("The app is loading ...")
loading_indicator = pn.indicators.Progress(value=state.progress, bar_color="primary")
return pn.Column(loading_message, loading_indicator)
return pn.pane.HoloViews(state.data.hvplot(), sizing_mode="stretch_both")
def load():
for _ in range(0,3):
time.sleep(1)
state.update(progress=state.progress+20)
state.update(data=pd.DataFrame({"x": [1,2], "y": [3,4]}))
icomponent = pn.bind(component, state=state.param.value)
pn.panel(icomponent, sizing_mode="stretch_both").servable()
pn.state.onload(load)