Hi folks,
I have a Dash app where I create a figure with a flexible amount of subplots (in this example controlled by the input). Until a certain amount everything is fine, but once too many graphs are given the title, ticks etc. shrinks to much and is not readable anymore.
I though of implementing a horizontal scrollbar, and fixing the size of each subplot.
Unfortunately I couldn’t find a way of implementing it.
Or is there a better way? Maybe with ScrollArea from Mantine Components? Any ideas?
from dash import Dash, html, Input, Output, dcc, callback
import plotly.graph_objects as go
import random
from plotly.subplots import make_subplots
@callback(
Output("scrollable-subplot", "children"),
Input("amount-of-graphs", "value")
)
def plot_all(value):
if value >=1:
fig = make_subplots(
rows=1,
cols=value,
horizontal_spacing=0.05,
shared_yaxes=True,
)
row = 1
column = 1
for _ in list(range(0,value)):
fig.add_trace(go.Scatter(
x=[1,2,3,4,5,6,7],
y=[random.randint(1,10) for _ in range(1,7)],
mode="lines",
),
row=row,
col=column)
column += 1
graph = dcc.Graph(figure=fig)
return graph
layout = html.Div(
children=[
dcc.Input(
value=1,
type="number",
id="amount-of-graphs"
),
html.Div(children=[
], id="scrollable-subplot"),
]),
app = Dash()
app.layout = layout
if __name__ == "__main__":
app.run(debug=True)