'How can I use dropDown for dash vtk purpose?

I can't write a proper callback for it, because I don't have enough experience in this. I'm trying to get a Container with all meshers but using the dropdown which will help me choose which vtk file or meshers I want to present.

import os
import dash
from dash import html
from dash import dcc
import dash_bootstrap_components as dbc
from dash.dependencies import Input, Output, State
import dash_vtk
from dash_vtk.utils import to_mesh_state
import vtk

app = dash.Dash()

choice_dd = html.Div([

dcc.Dropdown(
 id = "demo-dropdown",
                    style=dict(
                    width='70%',
                    verticalAlign="middle"
                ),
        options=[
            {'label': 'mesher1', 'value': 'm1'},            
            {'label': 'mesher2', 'value': 'm4'},
            {'label': 'mesher3', 'value': 'm2', 'disabled': True},
            {'label': 'mesher4', 'value': 'm3', 'disabled': True}
        ],
    ),
    html.Div(id='dd-output-container')
])

app.layout = dbc.Container(
    fluid=True,
    style={"height": "50vh"},
    children=[
        html.Br(),
        dbc.Row(
            [
                dbc.Col(
                    [
                        dcc.Markdown(
                            """
                # User Interface
                
                            """
                        )
                    ],
                    width=8,
                ),               
            ],
            align="end",
        ),
        html.Hr(),
        dbc.Tabs([
                dbc.Tab(label="Inputs", 
                children= [
                    dbc.Row(
                        children = [
                            dbc.Col(
                            width=4,
                            children=
                            dbc.Card(
                        [
                        dbc.CardHeader("Mesh Closure Type"), 
                        dbc.CardBody(choice_dd),
                        ]
                    ),
                ),
                dbc.Col(
                    width=8,
                    children =                        
                        [
                        html.Div([html.Div(id='container')]),
                        ],
                ),
            ],
        ),
        ]),
        ])
    ],
)

@app.callback(
    Output('container', 'children'),
                 Input('demo-dropdown', 'value'),)
def display_using_dd(result):

    file_name = os.path.join("/home/......")
    file_Reader = vtk.vtkXMLPolyDataReader()
    file_Reader.SetFileName(file_name)
    file_Reader.Update()
    sample_file = to_mesh_state(file_Reader.GetOutput())
      
    rep = dash_vtk.GeometryRepresentation(
        id="-rep",
        property={"edgeVisibility": True, 'color': (255, 255, 255)},
        children=[dash_vtk.Mesh(id="-mesh", state = sample_file ,)],
    )

    vtk_view = dash_vtk.View(
    children = rep
    )
    # first dropdown mesher1
    result = dbc.Container(
    children=[
        dbc.Row(
            [
                dbc.Col(
                    width=12,
                    children=dbc.Card(
                        [
                            dbc.CardBody(
                                children = rep,style={"height": "40%"}),
                        ],
                        style={"height": "80vh"},
                    ),
                ),
            ],
        ),
    ],)
    main_result =  dbc.Card(        [
            dbc.CardHeader("VTK Visualization"), 
            dbc.CardBody(result),
            ])
    
    # another code for the same as above for the mesher2, mesher3 .........etc

    return  main_result 


if __name__ == '__main__':
    app.run_server()


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source