集成的 dash-app(使用 django_plotly_dash)不够 space
Integrated dash-app (using django_plotly_dash) does not get enough space
我第一次将 dash-app 集成到 django 中。我为此使用 django_plotly_dash
。
我想我是按照标准方式做的:
urls.py
from django.urls import path, include
from . import views
urlpatterns = [
path('trial',views.trial,name='trial'),
]
views.py
from django.shortcuts import render
from django.http import HttpResponse
import my_first_dash_plotly_app.simple_dash_app
def trial(request):
return render(request, 'my_first_dash_plotly_app/trial.html')
simple_dash_app.py
import dash_core_components as dcc
import dash_html_components as html
import plotly.express as px
import pandas as pd
from django_plotly_dash import DjangoDash
app = DjangoDash('SimpleExample1')
# assume you have a "long-form" data frame
# see https://plotly.com/python/px-arguments/ for more options
df = pd.DataFrame({
"Fruit": ["Apples", "Oranges", "Bananas", "Apples", "Oranges", "Bananas"],
"Amount": [4, 1, 2, 2, 4, 5],
"City": ["SF", "SF", "SF", "Montreal", "Montreal", "Montreal"]
})
fig = px.bar(df, x="Fruit", y="Amount", color="City", barmode="group")
app.layout = html.Div(style={}, children=[
dcc.Graph(
id='example-graph-2',
figure=fig
)
])
trial.html
{%load plotly_dash%}
{%plotly_app name="SimpleExample1"%}
这只是 plotly/dash-introduction 中的标准示例。
它能正常工作,但看起来真的很丑。您必须滚动才能完整查看情节。
如果我没记错的话,我之前在 django 世界之外看到过这种行为。
有简单的解决方法吗?我应该就此提交错误报告,还是只是我做错了什么?我认为这种行为不应该是默认的:默认应该是每个图都得到它需要的大小。
我遇到了同样的问题,我通过在 plotly_app
标签中添加 ratio=1
来修复它。在您的情况下,这将是:
{% plotly_app name="SimpleExample1" ratio=1 %}
问题是标签的子 div
的高度为 0。ratio=1
修复了这个问题。
我第一次将 dash-app 集成到 django 中。我为此使用 django_plotly_dash
。
我想我是按照标准方式做的:
urls.py
from django.urls import path, include
from . import views
urlpatterns = [
path('trial',views.trial,name='trial'),
]
views.py
from django.shortcuts import render
from django.http import HttpResponse
import my_first_dash_plotly_app.simple_dash_app
def trial(request):
return render(request, 'my_first_dash_plotly_app/trial.html')
simple_dash_app.py
import dash_core_components as dcc
import dash_html_components as html
import plotly.express as px
import pandas as pd
from django_plotly_dash import DjangoDash
app = DjangoDash('SimpleExample1')
# assume you have a "long-form" data frame
# see https://plotly.com/python/px-arguments/ for more options
df = pd.DataFrame({
"Fruit": ["Apples", "Oranges", "Bananas", "Apples", "Oranges", "Bananas"],
"Amount": [4, 1, 2, 2, 4, 5],
"City": ["SF", "SF", "SF", "Montreal", "Montreal", "Montreal"]
})
fig = px.bar(df, x="Fruit", y="Amount", color="City", barmode="group")
app.layout = html.Div(style={}, children=[
dcc.Graph(
id='example-graph-2',
figure=fig
)
])
trial.html
{%load plotly_dash%}
{%plotly_app name="SimpleExample1"%}
这只是 plotly/dash-introduction 中的标准示例。
它能正常工作,但看起来真的很丑。您必须滚动才能完整查看情节。
有简单的解决方法吗?我应该就此提交错误报告,还是只是我做错了什么?我认为这种行为不应该是默认的:默认应该是每个图都得到它需要的大小。
我遇到了同样的问题,我通过在 plotly_app
标签中添加 ratio=1
来修复它。在您的情况下,这将是:
{% plotly_app name="SimpleExample1" ratio=1 %}
问题是标签的子 div
的高度为 0。ratio=1
修复了这个问题。