Hi,
I’m using django_plotly_dash for a webapp project but the plotly graph isn’t really responsive, so the view on mobile is terrible. I’m wondering is it possible to make it more responsive?
Below is my code.
test_plotly.py
import dash_core_components as dcc
import dash_html_components as html
from django_plotly_dash import DjangoDash
import plotly.graph_objects as go
app = DjangoDash('test_plotly',
meta_tags=[
{"name": "viewport", "content": "width=device-width, initial-scale=1"}
]
)
xaxis = [50000,60000,70000,80000,90000,100000,120000,
140000,160000,180000,200000,220000,240000,260000,280000, 300000]
yaxis = ['L1', 'L2','L3','L4','L5','L6','L7','L8','L9','L10','L11','L12','L13','L14','L15','L16']
fig2 = go.Figure(data = [go.Bar(name = 'Total', y = yaxis, x = xaxis, orientation='h')])
app.layout = html.Div(
style={'backgroundColor':'white', 'fontFamily': ["Segoe UI",]},
children=[
html.Div([
dcc.Graph(
id = 'test',
figure = fig2
)
])
])
test-plotly.html
{% extends 'survey/base.html' %}
{% load plotly_dash %}
{% block content %}
<H1 style ="text-align: center">Test</H1>
<hr>
<h2 style ="text-align: center">Plotly</h2>
{% plotly_app name="test_plotly" ratio=1 %}
{% endblock content %}
base.html is using basic bootstrap
<body style ='background-color:white'>
<main role="main" class="container">
<div class="cover-container d-flex w-100 h-100 p-3 mx-auto flex-column">
<div class = 'container' style = 'background-color:#ffffff'>
<div class="row justify-content-center">
<div class="col-12">
{% block content %}
{% endblock %}
</div>
</div>
</div>
</div>
</main>
</body>
The above looks great on a computer screen but when viewing on mobile, a scroll bar shows up on the plotly chart, see below. AND the graph doesn’t shrink proportionally. In this example, it seems like the graph is being squeezed horizontally.
If I change test-plotly.html to have a larger ratio, e.g.
{% plotly_app name="test_plotly" ratio=3 %}
that scroll bar will go away but it will also leave a very large white space below the chart, especially when viewing on a computer screen.
Is there anyway to make the graph more responsive (i.e. no scrolling bar and shrink proportionally, etc.) while not leaving a big white space?
Thanks!