I’m in trouble.
I want to display the serverside output data smoothly with hover data, but it is difficult.
Is it possible to improve the speed?
import numpy as np
import plotly.graph_objs as go
from dash_extensions.enrich import Output,Input,dash,DashProxy,ServersideOutput,ServersideOutputTransform,State
from dash import html, dcc
app = DashProxy(prevent_initial_callbacks = True,transforms = [ServersideOutputTransform()])
app.layout = html.Div([
dcc.Graph(id="my_graph",
style = {'width':500,
'height':500,
'display':"inline-block",
'verticalAlign':'top'},
),
dcc.Graph(id="curve",
style = {'width':500,
'height':500,
'display':"inline-block",
'verticalAlign':'top'},
),
html.Div(dcc.Store(id="da")),
html.Div(dcc.Store(id="d2")),
html.Div(dcc.Store(id="da3")),
dcc.Input (id = 'inputsubmit',type = 'text'),
html.Button ('aaa',id='a',n_clicks = 0)
])
@app.callback(
Output("curve", "figure"),
[Input("my_graph", "hoverData")],
[Input("da","data")],
[Input("d2","data")])
def update_graph(hoverData,da,da2):
if hoverData is None:
return dash.no_update
else:
selectx = hoverData['points'][0]['x']
selecty = hoverData['points'][0]['y']
rt = da[selecty,selectx,:]
rt2=da2[selecty,selectx,:]
fig2 = go.Figure()
fig2.add_trace(go.Scattergl(
x = rt,
y = rt2))
return fig2
@app.callback (
Output ('my_graph','figure'),
[Input ('da3','data')]
)
def image(da3):
fig3=go.Figure ()
fig3.add_trace (go.Heatmapgl (z = da3))
fig3.update_layout (yaxis = dict (scaleanchor = 'x'),plot_bgcolor = 'rgba(0,0,0,0)')
return fig3
#
@app.callback(
ServersideOutput('da', 'data'),
ServersideOutput('d2', 'data'),
ServersideOutput('da3', 'data'),
Input("a", "n_clicks"),
[State("inputsubmit", "value")]
)
def button(n_clicks,inputsubmit):
if inputsubmit is None:
return dash.no_update
else:
arr=np.random.rand (256,256,512)
arr2=np.random.rand (256,256,512)
heatmap=np.random.rand (256,256)
return arr,arr2,heatmap
app.run_server(debug=True,port=9080)