I want to plot two charts side by side (and not one above the other) in Dash by Plotly. The tutorials did not have an example where the graphs are plotted side by side.
I am writing the app.layout
in the following way
app.layout = html.Div(className = 'row', children=
[
html.H1("Tips database analysis (First dashboard)"),
dcc.Dropdown(id='d',
options = col_options,
value = 'Sun'),
dcc.Graph(id="graph1"),
dcc.Graph(id="graph2")
]
)
but after this graph1
appears above graph2
rather than side by side
The layout of a Dash app describes what the app looks like. The layout is a hierarchical tree of components. Dash HTML Components ( dash. html ) provides classes for all of the HTML tags and the keyword arguments describe the HTML attributes like style , class , and id .
Although they're both open source, Dash is more focused on the enterprise market and doesn't include all the features (such as job queues) in the open source version. By contrast, Streamlit is fully open source. Streamlit is more structured and focused more on simplicity.
Dash's component libraries, like dash_core_components and dash_html_components , are bundled with JavaScript and CSS files. Dash automatically checks with component libraries are being used in your application and will automatically serve these files in order to render the application.
You can achieve this by wrapping the graphs in a div
and adding display: inline-block
css property to each of the graphs.
app.layout = html.Div(className='row', children=[
html.H1("Tips database analysis (First dashboard)"),
dcc.Dropdown(),
html.Div(children=[
dcc.Graph(id="graph1", style={'display': 'inline-block'}),
dcc.Graph(id="graph2", style={'display': 'inline-block'})
])
])
Result
EDIT
I removed the display: flex
property from the wrapping div, and instead added the display: inline-block
property to each of the graphs. This makes it so the second graph does not get cut off, and will instead stack on smaller screens.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With