Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write an app layout in Dash such that two graphs are side by side?

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

like image 238
user2436437 Avatar asked Jun 19 '20 17:06

user2436437


People also ask

What is Dash app layout?

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 .

Which is better Streamlit or dash?

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.

Is CSS a dash component?

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.


1 Answers

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'})
    ])
])

ResultSide-by-side Graphs

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.

like image 146
ncasale Avatar answered Sep 25 '22 06:09

ncasale