Dear all,
I want to display vtu files using dash_vtk.
When you display the vtu file with paraview, it looks like this:
However, if you use the code below, the model will be displayed, but it will not be colored.
from dash import Dash, html
import os
import dash_vtk
from dash_vtk.utils import to_mesh_state
import vtk
# VTK file path
vtu_file_name = os.path.join("aaa.vtu")
# Read vtu file
vtu_file_Reader = vtk.vtkXMLUnstructuredGridReader()
vtu_file_Reader.SetFileName(vtu_file_name)
vtu_file_Reader.Update()
# Get data set
dataset = vtu_file_Reader.GetOutput()
content = dash_vtk.View(
children=[
dash_vtk.GeometryRepresentation(
children=[
dash_vtk.Mesh(
state=to_mesh_state(dataset),
),
],
mapper={
"colorByArrayName":"data",
"scalarMode": 1,
"interpolateScalarsBeforeMapping": True,
"useLookupTableScalarRange":True,
"colorMode":1,
"GetArray":1,
"scalarVisibility":True,
},
property={
"edgeVisibility": False,
'representation': 2,
},
actor={
"visibility":1,
},
colorMapPreset="rainbow",
)
],
)
# Dash setup
app = Dash(__name__)
server = app.server
app.layout = html.Div(
style={"width": "100%", "height": "400px"},
children=[content],
)
if __name__ == "__main__":
app.run(debug=True)
Any advice on where I’m going wrong?
Thanks!