【发布时间】:2021-03-15 19:31:15
【问题描述】:
我一直在尝试将构建多页应用程序示例 https://dash.plotly.com/urls 与 Dash 引导组件简单侧边栏示例:https://dash-bootstrap-components.opensource.faculty.ai/examples/simple-sidebar/page-1 结合起来。它在第一次加载时工作并正确显示,但是每次我从一个页面导航到另一个页面时,主 div 被推得越来越远,相对填充似乎随着每个页面的变化而增加。我该如何避免这种情况?
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import dash_bootstrap_components as dbc
import dash
from app import app
# the style arguments for the sidebar. We use position:fixed and a fixed width
SIDEBAR_STYLE = {
"position": "fixed",
"top": 0,
"left": 0,
"bottom": 0,
"width": "16rem",
"padding": "2rem 1rem",
"background-color": "#f8f9fa",
}
# the styles for the main content position it to the right of the sidebar and
# add some padding.
CONTENT_STYLE = {
"margin-left": "18rem",
"margin-right": "2rem",
"padding": "2rem 1rem",
}
sidebar = html.Div(
[
dbc.Nav(
[
dbc.NavLink("Home", href="/", active="exact"),
dbc.NavLink("Page 1", href="/apps/app1", active="exact"),
dbc.NavLink("Page 2", href="/apps/app2", active="exact"),
],
vertical=True,
pills=True,
),
],
style=SIDEBAR_STYLE,
)
content = html.Div(id="page-content",
style=CONTENT_STYLE,
children = (html.P("I am the main div")
))
layout = html.Div([
sidebar,
content
])
【问题讨论】:
-
我无法重现您共享的代码的问题,您的回调是什么样的?
-
感谢您的浏览,我意识到我的错误是在组合示例时,我为两个嵌套的 DIV 分配了相同的 ID“页面内容”。我会发布一个完整的答案。
标签: python html css plotly-dash