Skip to content

Commit 47cc613

Browse files
committed
Explain graph_in_tabs example better
1 parent 5883af7 commit 47cc613

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

examples/advanced-component-usage/graphs_in_tabs.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
"""
2-
A simple app demonstrating how to dynamically render tab content containing
3-
dcc.Graph components to ensure graphs get sized correctly. We also show how
4-
dcc.Store can be used to cache the results of an expensive graph generation
5-
process so that switching tabs is fast.
2+
When rendering Plotly graphs as the children of tabs, sometimes the graph will not be
3+
sized correctly if it wasn't initially visible. The solution to this problem is to
4+
render the tab content dynamically using a callback.
5+
6+
This example shows how to do that, and also shows how to use a dcc.Store component to
7+
cache the graph data so that if the generating process is slow, the graph still renders
8+
quickly when the user switches tabs.
69
"""
710

811
import time
@@ -13,13 +16,17 @@
1316
import plotly.graph_objs as go
1417
from dash import Input, Output, dcc, html
1518

19+
EXPLAINER = """This example shows how to use callbacks to render graphs inside tab
20+
content to ensure that they are sized correctly when switching tabs. It also
21+
demonstrates use of a `dcc.Store` component to cache graph data so that if the data
22+
generating process is expensive, switching tabs is still quick."""
23+
1624
app = dash.Dash(external_stylesheets=[dbc.themes.BOOTSTRAP])
1725

1826
app.layout = dbc.Container(
1927
[
20-
dcc.Store(id="store"),
2128
html.H1("Dynamically rendered tab content"),
22-
html.Hr(),
29+
dcc.Markdown(EXPLAINER),
2330
dbc.Button(
2431
"Regenerate graphs",
2532
color="primary",
@@ -34,7 +41,16 @@
3441
id="tabs",
3542
active_tab="scatter",
3643
),
37-
html.Div(id="tab-content", className="p-4"),
44+
# we wrap the store and tab content with a spinner so that when the
45+
# data is being regenerated the spinner shows. delay_show means we
46+
# don't see the spinner flicker when switching tabs
47+
dbc.Spinner(
48+
[
49+
dcc.Store(id="store"),
50+
html.Div(id="tab-content", className="p-4"),
51+
],
52+
delay_show=100,
53+
),
3854
]
3955
)
4056

0 commit comments

Comments
 (0)