昨天我第一次见到了plot.ly dash并创建了一些互动情节.我添加了dash_core_components.Slider()如下代码的对象.
dcc.Slider(
id='month--slider',
min=0,
max=12,
value=12,
step=None,
marks={'1': '1', '6': '6', '12': {'label': '12', 'style': {'color': 'red'}}}
)
Run Code Online (Sandbox Code Playgroud)
我已经阅读help(dcc.Slider)但我无法找到改变下方滑块天蓝色的方法.
所以我的问题在这里......是否可以更改plot.ly dash的默认滑块的颜色(或样式)?先感谢您.
我一直在尝试从 Polty Dash 开发一个多页模板应用程序。我正在尝试在成功登录时实现重定向。该项目的结构如下:
multipage
??? app.py
??? apps
? ??? app1.py
? ??? app2.py
? ??? app3.py
??? index.py
??? static
??? base.css
Run Code Online (Sandbox Code Playgroud)
我的代码如下:
index.py(起点)
from dash.dependencies import Input, Output
import dash_core_components as dcc
import dash_html_components as html
from app import app, server
from apps import app1, app2, app3
app.layout = html.Div([
dcc.Location(id='url', refresh=False),
html.Div(id='page-content')
])
@app.callback(Output('page-content', 'children'),
[Input('url', 'pathname')])
def display_page(pathname):
if pathname == '/':
return app3.layout
else:
return '404'
if __name__ == '__main__':
server.run(debug=True)
Run Code Online (Sandbox Code Playgroud)
在这里,当用户访问/登录页面(app3.py)时将呈现。 …
我已经能够使用传递给 dash_core_components.Graph 的字典(配置)成功修改 Dash 中 Plotly 的工具栏
现在我想将其余按钮的“工具提示”或标签更改为另一种语言。文档说明我可以使用“locale”参数更改标签的 de locale(语言)。我在 JavaScript 和 R 文档中都看到了这一点,它们被应用于 Plotly Graphs 或 dash_core_components.Graph:
现在我需要在 Python 中做到这一点,但我一直无法做到这一点。这是我尝试过的:
config_plots = {'modeBarButtonsToRemove':["sendDataToCloud","lasso2d","pan2d","autoScale2d","select2d","zoom2d","zoomIn2d", "zoomOut2d"],
"locale":"de"}
dcc.Graph(id="plot",config=config_plots,
figure={"data":plotdata,"layout":layout})
Run Code Online (Sandbox Code Playgroud)
我也将 locale 参数添加到 plotly 图形 (plotly.graph_objs) 并尝试使用我知道存在的不同语言环境,但到目前为止我没有运气。
问题:如何自定义标签的文本?我是否缺少使用 locale 参数的东西?有什么方法可以更改标签的文本,以便我可以在不使用 locale 参数的情况下翻译它?
请注意,我对 JavaScript 知之甚少,所以如果可能的话,我更愿意在 Python 中执行此操作
我构建了一个Flask应用程序,我想使用Plotly为我的数据嵌入一个图表。我对Plotly进行了一些研究,发现它与Dash有关,并且在确定我的项目需要使用这两个方法中的哪一个时遇到了一些麻烦。它们之间有什么区别?
我怎样才能得到一个小标签,告诉我我在 Dash for python 的滑块上选择了什么数字?我正在使用 dash_core_components.Slider()。
在我的基于Dash的应用程序中,一个按钮会触发一个长时间运行的计算。在结果尚未出现时显示加载动画,并使按钮处于非活动状态,以便在计算完成之前不会再次单击它,这不是很好吗?
我正在使用Bulma进行 UI 设计,并希望button is-loading为此目的使用CSS 类。
我的第一个想法是有两个回调:一个由单击按钮触发以将按钮设置为is-loading,另一个由输出更改触发以将其设置回正常。
@app.callback(
Output('enter-button', 'className'),
[
Input('graph', 'figure')
],
)
def set_trend_enter_button_loading(figure_changed):
return "button is-large is-primary is-outlined"
@app.callback(
Output('enter-button', 'className'),
[
Input('enter-button', 'n_clicks')
],
)
def set_trend_enter_button_loading(n_clicks):
return "button is-large is-primary is-outlined is-loading"
Run Code Online (Sandbox Code Playgroud)
显然它不能那样工作:
dash.exceptions.CantHaveMultipleOutputs:
You have already assigned a callback to the output
with ID "enter-button" and property "className". An output can only have
a single callback function. Try combining your inputs and
callback functions together …Run Code Online (Sandbox Code Playgroud) 我正在尝试计算两个纬度/经度之间的方位。
我对功能/公式本身没有疑问,
提供:
def get_bearing(lat1, long1, lat2, long2):
dLon = (long2 - long1)
y = math.sin(dLon) * math.cos(lat2)
x = math.cos(lat1) * math.sin(lat2) - math.sin(lat1) * math.cos(lat2) * math.cos(dLon)
brng = math.atan2(y, x)
brng = np.rad2deg(brng)
return brng
Run Code Online (Sandbox Code Playgroud)
问题是结果不是预期的。
该函数的预期用途返回(很长)列表中两个经纬度对之间的方位,即
lat1 = path[int(len(path) * location / 1000)][0]
lat2 = path[int(len(path) * location / 1000) + 1][0]
lng1 = path[int(len(path) * location / 1000)][1]
lng2 = path[int(len(path) * location / 1000) + 1][1]
Run Code Online (Sandbox Code Playgroud)
然后,方位结果会更改图的视图方向,其中方位可以采用[-180,180]范围内的值。理想情况下,结果应显示为使得lat1,lng1和lat2,lng2之间形成的线在图中完全是“垂直”的(在图中切换了经纬度注释),请参见下文
我希望有人可以从函数返回的方位以及预期方位应该是什么来推断问题。以下是一些实例:
Current Location: 30.07134 -97.23076
Next …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用循环打印图表。数据在一个列表中。这是我的代码当前的样子(我在 for 循环中收到语法错误):
import dash
import dash_core_components as dcc
import dash_html_components as html
import pandas as pd
import plotly.graph_objs as go
dfs = [pd.DataFrame({"xaxis":["thing","otherthing","anotherthing"],"yaxis":[64,14,62]}),pd.DataFrame({"xaxis":["newthing","newotherthing","newanotherthing"],"yaxis":[344,554,112]})]
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
g = 0
app.layout = html.Div(children=[
for df in dfs:
dcc.Graph(id='example-graph'+str(g),figure={'data': [go.Bar(x=df['xaxis'],y=df[("yaxis")],name="yaxis")]})
]
g = g + 1)
if __name__ == '__main__':
app.run_server(debug=True)
Run Code Online (Sandbox Code Playgroud)
我该怎么做呢?
提前致谢。
编辑 08/03/19:我知道我可以在下面的两个图表中手动编码,但我希望将其放入循环中,因为将来我可能会在一页上显示 2 个以上的图表。
import dash
import dash_core_components as dcc
import dash_html_components as html
import pandas as pd
import plotly.graph_objs as go
df1 …Run Code Online (Sandbox Code Playgroud) 我很好奇是否可以在短划线的 children 属性中设置某些单词的样式。
我的文本是 children 属性的一部分,因为我有一个更新文本的回调。但是,我只想将冒号前的单词加粗,而不是整个文本。我似乎无法在 Dash 中找到一种优雅的方法来做到这一点。
我的样子带回家的工资总额:500 我希望它看起来像带回家的工资总额: 500
当前代码
html.Div([
html.Div([
html.Div(id='total-pay',
children='',
style={'font-weight': 'bold'}
),
], className='six columns'),
], className='row'),
@app.callback(
Output('total-pay', 'children'),
[Input('date-picker-range', 'start_date'),
Input('date-picker-range', 'end_date')],
)
def dataview_text(start_date, end_date):
df = df_paystub
df = df[(df['Date'] >= start_date) & (df['Date'] <= end_date)]
totalpay = 'Take Home Pay Total: ' + str(round(df['CheckTotal'].sum(),2))
return totalpay
Run Code Online (Sandbox Code Playgroud)
谢谢!
plotly-dash ×10
python ×7
plotly ×5
python-3.x ×2
charts ×1
css ×1
dashboard ×1
flask ×1
function ×1