【发布时间】:2018-11-23 11:38:32
【问题描述】:
我想将 CSS 样式表或 <style> 块提供给 Python Dash 应用程序。我试图在下面做这两件事,但都不适合我。应用加载正常,但文本仍然是黑色,而不是绿色。
import dash
from dash.dependencies import Input, Output
import dash_core_components as dcc
import dash_html_components as html
import plotly.graph_objs as go
from flask import send_from_directory
# define the app
app = dash.Dash()
app.head = [html.Link(rel='stylesheet', href='./static/stylesheet.css'),
('''
<style type="text/css">
h1 {
color:green;
}
</style>
''')]
app.layout = html.Div(html.H1('Hello World!'))
if __name__ == '__main__':
app.run_server(debug=True)
在./static/stylesheet.css 里面是一个只有这个的文件:
h1{
color:green;
}
我试过只使用样式表或只使用 <style> 标记,但这些都没有将 h1 标记变为绿色。
这是我为解决我的问题所做的研究:
https://github.com/plotly/dash/pull/171
https://dash.plot.ly/external-resources
https://github.com/plotly/dash-recipes/blob/master/dash-local-css-link.py
我唯一没有尝试过的(那些链接建议的)是从外部链接 (CDN) 加载。但是我希望能够离线加载这个应用程序,所以这不是一个选项。
【问题讨论】:
标签: python css plotly-dash