I have the feeling I am just missing something, but how do you make a layout mobile responsive? I am using bootstrap’s css.
Here is the minimum example:
import dash
import dash_core_components as dcc
import dash_html_components as html
app = dash.Dash()
app.layout = (
html.Div(
html.Div(
html.Div(
html.Button('Some very long text so we can see centering and styling', className='btn btn-secondary'),
className='col-md-6 col-xs-12'),
className='row justify-content-center'),
className='container')
)
app.css.append_css({
"external_url": "https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css"
})
if __name__ == '__main__':
app.run_server(debug=True)
If you prefer, Dash also lets you override the default html template into which your app gets injected, check out the docs.
Finally, since you’re using Bootstrap, you might be interested in checking out dash-bootstrap-components (full disclosure, I’m one of the developers working on it),
How have you constructed the layout? Those meta tags will only ensure that the CSS responds to the real viewport size rather than a virtual one (mobile devices generally pretend their screen is larger than it is then scale content down so that non-responsive websites don’t look terrible). To make the layout reorganise itself appropriately on small screens you need to tell it how to do that.
I would suggest using dbc.Row and dbc.Col to control the layout rather than setting float property in your style arguments. They can be configured to take up different widths on different screen sizes. More generally to achieve responsiveness you’ll need to use CSS (whether bootstrap or your own) rather than inline style arguments as generally you need to make use of media queries to achieve different behaviour on different screen sizes.
@tcbegley I am embedding a Dash app in an iFrame in a React component. The react app has a minimal navbar and layout, and the Dash app should fill the entirety of the available space. The React app and the Dash app are served from the same server (same origin), so CORS is not an issue.
Do you have a best-practice for ensuring the iFrame fills the available viewport? I have used react-iframe-resizer-super and iframe-resizer-react to implement this but it has been tough to get the iframe to fill all available space.
I haven’t used the iframe approach much, but when I did I just set style="width:100vw;height:100vh" on the <iframe /> to make it fill the available space. I’m not familiar with the iframe resizer libraries you mention I’m afraid.
If the enclosing react app is just being used to add a navbar and some layout, I would see if you can either replicate that in Dash, or alternatively modify the index string (the HTML template that the Dash app gets injected into). This latter approach is what I did on the dash-bootstrap-components documentation and it has worked very well for me.
do you know how to inject Dash app state from the React app?
When I looked at this in the past, I think I concluded it wasn’t really possible. I think you’re right that something is possible in this direction with Dash enterprise, but I haven’t really used it. If you need to communicate with components outside the app, probably the easiest thing is to first see if you definitely can’t move those components into the app and use callbacks etc. to share information.