plotly / dash-slicer

A volume slicer for Dash
https://dash.plotly.com/slicer
MIT License
24 stars 7 forks source link

How to run dash-slicer in the @app.callback? #55

Open mareksocha opened 3 years ago

mareksocha commented 3 years ago

Hi, I am strugling to make dash-slicer work in the app.callback. Here is my code:

import dash
import dash_html_components as html
import imageio
from dash_slicer import VolumeSlicer

app = dash.Dash(__name__, update_title=None)

app.layout = html.Div(
    children=[
        html.Button('Randomize', id='random_button', n_clicks=0),
        html.Div(id='series_viewer')
    ]
)

@app.callback(
    dash.dependencies.Output('series_viewer', 'children'),
    dash.dependencies.Input('random_button', 'n_clicks')
)
def show(n_clicks):
    vol = imageio.volread("imageio:stent.npz")
    slicer = VolumeSlicer(app, vol)
    slicer.graph.config["scrollZoom"] = False
    return slicer.graph, slicer.slider, *slicer.stores

if __name__ == "__main__":
    app.run_server(debug=True, dev_tools_props_check=False)

What I am getting is: obraz

Where there should be an image over the slider. Is there any way to make it work?

This code is based on the example from: Introduction to Dash Slicer

mareksocha commented 3 years ago

Okay, I have read previous issues and it seams there is no way to make it work like I intend it to work. The volume must be known before the callback happens. That's a pity :( I hope option to work with callbacks will be added in the future versions...

guigautier commented 2 years ago

Hope too