Hi,
I’m trying to render a live point cloud & trajectory and I’m currently using global
variables to do this. However, this isn’t ideal, but I can’t figure out the proper gluing logic such that I can free myself of them. Below is a dummy script, and I marked with comments my questions.
app = dash.Dash(__name__)
app.layout = html.Div(
[
dash.dcc.Graph(id='live-graph'),
dash.dcc.Interval(id='time', interval=1000),
],
style={"display": "inline-block"}
)
path_history = [[], [], []]
map_history = [[], [], []]
@app.callback(Output('live-graph', 'figure'),
[
Input('time', 'n_intervals')
]
)
def update(t):
global path_history, map_history
if t is None:
return dash.no_update
x, y, z = P[t % len(P)]
x_map, y_map, z_map = zip(*M[t*step:(t+1)*step])
path_history[0].append(x) # <-- the same as below
path_history[1].append(y)
path_history[2].append(-z)
map_history[0].extend(x_map) # <-- this is very expensive. if I have a huge point cloud, it's getting laggy; how can I keep the values that I currently plotted on during the next update?
map_history[1].extend(y_map)
map_history[2].extend(z_map)
fig = go.Figure(data={'data':
[
go.Scatter3d(x=path_history[0],
y=path_history[1],
z=path_history[2],
mode='lines+markers',
name='path',
marker=dict(size=2, color='red')),
go.Scatter3d(x=map_history[0],
y=map_history[1],
z=map_history[2],
mode='markers',
name='map',
marker=dict(size=1, color='navy', symbol='diamond'))
]
}
)
fig.update_layout(
uirevision='constant',
width=1500,
height=1500,
scene=dict(xaxis=dict(range=[-10, 10]), yaxis=dict(range=[-10, 10]), zaxis=dict(range=[0, 3]))
)
return fig
if __name__ == '__main__':
port = 8888
M, P = load_map_and_path()
step = len(M) // len(P)
camera = dict(eye=dict(x=0., y=2.5, z=0.))
app.run_server(debug=True, port=port)
Thanks!