Hi everyone,
I have been playing around with dash-slicer (which I think it’s amazing!), and I was trying to build a simple dashboard where one would have just one view, but the plane of view (transversal, coronal, sagittal) could be updated. I haven’t managed to achieve this, so far what I was trying is doing something like this:
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output, State
from dash_slicer import VolumeSlicer
import jupyterlab_dash
import image
app = dash.Dash(__name__, update_title=None)
viewer = jupyterlab_dash.AppViewer()
vol = imageio.volread("imageio:stent.npz")
slicer = VolumeSlicer(app, vol)
app.layout = html.Div(
[html.Div([dcc.Dropdown(id="plane-dropdown",
options=[
{'label': 'Axial', 'value': 0},
{'label': 'Sagittal', 'value': 1},
{'label': 'Coronal', 'value': 2}
], value=0)]),
html.Div([slicer.graph, slicer.slider, *slicer.stores]),
html.Div(id='test',children=[])]
)
@app.callback(
Output(slicer.state.id, 'data'),
Input('plane-dropdown', 'value'),
State(slicer.state.id, 'data'),
prevent_initial_call=True)
def update_plane(plane, state):
state['axis']=plane
return state
viewer.show(app)
But I think that it may not be possible, because if I understand correctly the code the slicer state is not supposed to be used as an output. If changing the axis
property is not a feasible way to “dynamically” change the plane of view, what would be another way? I tried to use different slicer.graph
objects (each of them initialised with a different axis
value) and switch among them updating the children
parameter of a div
, but it did not work out as well. Any suggestion?