So, in order to maintain uirevision, ie moving the camera around, you need to pass this to the layout:
uirevision=True
I can get the slide to move through the object easily with a clientside callback. It’s still not ultra smooth, do probably just to the amount of data:
import numpy as np
# DASH
import dash
from dash import Dash, dcc, html, Input, Output, State
import dash_bootstrap_components as dbc
#from dash_slicer import VolumeSlicer
#from jupyter_dash import JupyterDash
#JupyterDash.infer_jupyter_proxy_config()
# GRAPHS
import plotly.graph_objects as go
from plotly.subplots import make_subplots
path = "C:\\Users\\*\\Downloads\\dataSample\\"
# LOAD DATA
fx = np.loadtxt(path+"fx.txt")
fy = np.loadtxt(path+"fy.txt")
fz = np.loadtxt(path+"fz.txt")
fi = np.loadtxt(path+"fi.txt")
fj = np.loadtxt(path+"fj.txt")
fk = np.loadtxt(path+"fk.txt")
makersOpacity = 0.18
markerColor = "#244063"
# DISPLAY LUNG MESH
fig_mesh = make_subplots(rows= 1, cols=1, specs=[[{"type": "scene"}]])
fig_mesh.add_trace(go.Mesh3d(x=fz, y=fy, z=fx, opacity=1, i=fk, j=fj, k=fi, color='#0be02f', name= "Fixed Image", showlegend=False, flatshading = False), row=1, col=1)
fig_mesh.add_trace(go.Mesh3d(
# 8 vertices of a rectangle
x=[130, 130, 360, 360, 130, 130, 360, 360],
y=[250, 251, 251, 250, 250, 251, 251, 250], # CORONAL MARKER
z=[150, 150, 150, 150, 400, 400, 400, 400],
i = [7, 0, 0, 0, 4, 4, 6, 6, 4, 0, 3, 2],
j = [3, 4, 1, 2, 5, 6, 5, 2, 0, 1, 6, 3],
k = [0, 7, 2, 3, 6, 7, 1, 1, 5, 5, 7, 6],
opacity=makersOpacity,
color= markerColor,
name = "Coronal Marker",
showlegend=False,
flatshading = False
), row=1, col=1)
### SETTING CAMERA ANGLE FOR VIEW ###
camera_settings = dict(
up=dict(x=1, y=0, z=1),
center=dict(x=0, y=0, z=0),
eye=dict(x=-1.2, y=-1.5, z=0.8)
)
### LAYOUT FOR SCENCE OR 3D ANIMATION ###
fig_mesh.update_layout(scene_camera= camera_settings,
scene=dict(
xaxis=dict(showticklabels=False, visible=False),
yaxis=dict(showticklabels=False, visible=False),
zaxis=dict(showticklabels=False, visible=False)),
width=800, height=600, paper_bgcolor='rgba(0,0,0,0.5)',
uirevision=True)
# DASH
app = Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP, dbc.icons.FONT_AWESOME])
app.layout = html.Div(children=[
dcc.Graph(
id='lungMesh',
figure=fig_mesh
),
html.Div(
[
dcc.Slider(
id='coronalSlider',
min=160.,
max=360,
step=1,
value=0,
marks=None,
updatemode='drag',
),
],
style=dict(width='50%'),
),
])
app.clientside_callback(
"""
function(corVal, fig) {
newFig = JSON.parse(JSON.stringify(fig))
newFig['data'][1]['y'] = [corVal,corVal+1, corVal+1, corVal, corVal, corVal+1, corVal+1, corVal]
return newFig
}
""",
Output('lungMesh', 'figure'),
Input('coronalSlider', 'value'),
State('lungMesh', 'figure'),
prevent_initial_call=True)
app.run(debug=True)