I have partially working solution to hide/show Slider component by updating Dropdown component. The code does what I want it to but I'm getting an error on the webpage:
Invalid prop for this component: Property "style" was used with component ID: "slider" in one of the Output items of a callback. This ID is assigned to a dash_core_components.Slider component in the layout, which does not support this property. This ID was used in the callback(s) for Output(s):slider.style
Is it possible to hide Slider component using other property? Thank you.
app.layout = html.Div([
dcc.Graph(
id='CZmap'
),
html.Label('Dropdown'),
dcc.Dropdown(
id='dropdown',
options=[
{'label': 'Kraje', 'value': 'Kraje'},
{'label': 'Obce', 'value': 'Obce'}
],
value='Obce'
),
# Create Div to place a conditionally visible element inside
html.Div([
# Create element to hide/show, in this case an 'Input Component'
dcc.Slider
(
id='slider',
min=1,
max=4,
step=1,
value=1,
marks={str(i): str(i) for i in range(1,5)}
)
], style= {'display': 'block'} # <-- This is the line that will be changed by the dropdown callback
)
])
@app.callback(
Output(component_id='slider', component_property='style'),
[Input(component_id='dropdown', component_property='value')])
def show_hide_element(visibility_state):
if visibility_state == 'Kraje':
return {'display': 'block'}
if visibility_state == 'Obce':
return {'display': 'none'}
if __name__ == '__main__':
app.run_server(debug=True)```
[1]: https://stackoverflow.com/questions/50213761/changing-visibility-of-a-dash-component-by-updating-other-component