我想在单击按钮时更改选项卡。如何切换标签页?
app.layout = html.Div(children=[
html.H1(children=title),
dcc.Markdown(header),
dcc.Tabs(id='graphs', children=[
dcc.Tab(label='Run', children=html.Div(children=form), value=10),
dcc.Tab(id='result', label='Result', children=graphs, value=1)],
value=10)])
@app.callback(Output('result', 'children'),
[Input('run_btn', 'n_clicks')],
inputs)
def call_simulation(clicks, *params):
params = dict(zip(parameter_mask.keys(), params))
if clicks is not None:
print(params)
try:
simulation(params)
SWITCH TO RESULT TAB
except Exception as e:
print(e)
return html.Div(children=["The simulation produced an error with this particular parameterisation", str(type(e)), str(e)])
return generate_graph_layout(newest_subdirectory('./result', ''))
else:
return html.Div()
Run Code Online (Sandbox Code Playgroud) 我已经使用 Dash-Cytoscape 两天了,我尝试了很多方法来单独更改节点大小。我试过这个,但没有用:
import dash
import dash_cytoscape as cyto
import dash_html_components as html
app = dash.Dash(__name__)
app.layout = html.Div([
cyto.Cytoscape(
id="cytospace",
elements=[
{'data': {'id': 'one', 'label': 'Node 1'}, 'position': {'x': 50, 'y': 50}, 'size':20},
{'data': {'id': 'two', 'label': 'Node 2'}, 'position': {'x': 200, 'y': 200}, 'size':70},
{'data': {'source': 'one', 'target': 'two','label': 'Node 1 to 2'}}
],
layout={'name':'preset'},
style={'height': '95vh',
'width': '100%'}
)
])
if __name__ == "__main__":
app.run_server(debug=True)
Run Code Online (Sandbox Code Playgroud) 我有一个脚本,它每小时收集数据并使用 Plotly Dash 将其可视化。
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import plotly.express as px
import pandas as pd
df = pd.read_csv("/home/pi/backup/data/data.csv").sort_values(by="Number")
df["Datetime"] = df["Datetime"].str.replace("T", " ").str.replace("Z", "")
df["Datetime"] = pd.to_datetime(df["Datetime"], format="%Y-%m-%d %H:%M:%S")
df["Datetime"] = df["Datetime"].dt.floor("H")
grouped = df.groupby(["Datetime", "Number", "Shop"]).min().reset_index()
app = dash.Dash(__name__)
tabs_styles = {
'height': '30px'
}
tab_style = {
'borderBottom': '1px solid #d6d6d6',
'padding': '6px',
'fontWeight': 'bold'
}
tab_selected_style = {
'borderTop': '1px solid #d6d6d6',
'borderBottom': '1px solid …Run Code Online (Sandbox Code Playgroud) Plotly 图形上缺少用于绘制图形的 x 和 y 列表中的数据点。我不知道为什么。
x_axist_list 是年-周格式的列表。例如,2019-43 就是 2019 年的第 43 周。
x_axis_list = ['2019-00', '2019-01', '2019-02',.....'2019-54']
y_axis_list = [0,0,0,....1,2,0,0]
Run Code Online (Sandbox Code Playgroud)
当我使用 Plotly 绘制出来时:
my_fig = px.line(x=x_axis_list, y=y_axis_list,\
labels=dict(time_from_db="Time", \
num_of_accidents_from_db="Num of Accidents"), \
title="Number of Accidents Per Week")
dcc.Graph(id='my_fig', figure=my_fig)
Run Code Online (Sandbox Code Playgroud)
目前我有一个 pandas 数据框:
df = pd.DataFrame({
"date": ["20210613", "20210614", "20210615"],
"user": ["A\nB", "C", "D"],
"machine" : [1, 0, 3]
})
Run Code Online (Sandbox Code Playgroud)
我想知道是否有任何方法可以将此表打印到我的破折号应用程序中,如下所示:
无论使用纯文本打印到 dcc.Textarea 还是 dash_table.DataTable 都可以。
目前我还没有找到一个好的方法来实现这一点,非常感谢。
这是通过 Dash 示例创建多标头表的示例:
\nimport dash\nimport dash_table\nimport pandas as pd\n\napp = dash.Dash(__name__)\n\napp.layout = dash_table.DataTable(\n columns=[\n {"name": ["", "Year"], "id": "year"},\n {"name": ["City", "Montreal"], "id": "montreal"},\n {"name": ["City", "Toronto"], "id": "toronto"},\n {"name": ["City", "Ottawa"], "id": "ottawa"},\n {"name": ["City", "Vancouver"], "id": "vancouver"},\n {"name": ["Climate", "Temperature"], "id": "temp"},\n {"name": ["Climate", "Humidity"], "id": "humidity"},\n ],\n data=[\n {\n "year": i,\n "montreal": i * 10,\n "toronto": i * 100,\n "ottawa": i * -1,\n "vancouver": i * -10,\n "temp": i * -100,\n "humidity": i * 5,\n }\n …Run Code Online (Sandbox Code Playgroud) plotly-dash ×6
plotly ×3
python ×3
cytoscape ×1
dataframe ×1
datatable ×1
pandas ×1
python-3.x ×1