我正在使用Dash创建仪表板,我想通过悬停表格来显示文本,以便我可以使用该信息进一步更新不同的图形,以下是我正在使用的示例数据的代码
import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly.graph_objs as go
from dash.dependencies import Input, Output
import pandas as pd
import json
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/2014_usa_states.csv')
# Launch the application:
app = dash.Dash()
# Create a Dash layout that contains a Graph component:
app.layout = html.Div([
html.Div([
dcc.Graph(
id='table',
figure={
'data': [
go.Table(
header=dict(values=list(df.columns),
fill = dict(color='#C2D4FF'),
align = ['left'] * 5),
cells=dict(values=[df.Rank, df.State, df.Postal, df.Population],
fill = dict(color='#F5F8FF'),
align = ['left'] * 5)
)
],
'layout': go.Layout(
title = 'US - Population',
hovermode='closest'
)
}
)], style={'width':'60%', 'float':'left'}),
html.Div([
html.Pre(id='hover-data', style={'paddingTop':35})
], style={'width':'30%'})
])
@app.callback(
Output('hover-data', 'children'),
[Input('table', 'hoverData')])
def callback_image(hoverData):
return json.dumps(hoverData, indent=2)
if __name__ == '__main__':
app.run_server()
但是它没有报告任何事情。请帮助我。