【发布时间】:2021-01-24 04:19:51
【问题描述】:
我正在尝试使用回调为破折号 data_table 创建工具提示。但是我多次尝试都没有成功。
我已经看到通过从路径读取 csv 来创建工具提示的示例。但在我的情况下,数据框是在回调函数中创建的,并在单击提交按钮后返回。下面是我正在使用的代码
display_cols=["col1","col2","col3","col4"]
columns_property=[{"name": i, "id": i, "deletable": False, "selectable": True, "renamable":True, "hideable":True} for i in display_cols]
dash_table.DataTable(id="table",
columns=columns_property,data=[],fill_width=True,
export_columns="all",export_format="xlsx", sort_action="native",is_focused=True,
sort_mode="multi",export_headers ="names",editable=True,tooltip_data=tooltip,## Tootlip is returned from callback as options
style_cell={'textAlign': 'left','border': '1px solid grey',
'whiteSpace':'normal','height':'auto'},
style_header={'backgroundColor': 'white','fontWeight': 'bold',
'border': '1px solid black'},
style_table={'fontFamily': 'Open Sans',
'textAlign': 'right',
'whiteSpace': 'no-wrap',
'overflowX': 'scroll',
'minWidth': '100%',
'height': '600px',
'overflowY': 'scroll'})
@app.callback([Output('table', 'data'),Output("tooltip", "options") ],
[Input('submit3', 'n_clicks')],
[
State('input1', 'value'),
State('input2', 'value')
]
)
def update_output(clicked, input1, input2):
if clicked:
input_file=input1
model_path=input2
""" Some Code for Generatng DF"""
df=df[["col1","col2","col3","col4"]]
tooltip_data= [{c:{'type': 'text', 'value': f'{r},{c}'} for c in df.columns} for r in df[df.columns].values]
return list(df.to_dict("index").values()), tooltip_data
【问题讨论】:
标签: plotly-dash