Hide and Unhide Dropdown

Hello Team,

I would like to launch my Dash with my dropdown hide and after selecting something on another dropdown unhide my first dropdown.

This is a little example :

import dash
from dash.dependencies import Input, Output
import dash_core_components as dcc
import dash_html_components as html

app = dash.Dash('example')

app.layout = html.Div([
        id = 'dropdown-to-show_or_hide-element',
            {'label': 'Show element', 'value': 'on'},
            {'label': 'Hide element', 'value': 'off'}
        value = 'off'

    # Create Div to place a conditionally visible element inside
        # Create element to hide/show, in this case an 'Input Component'
        id = 'element-to-hide',
        placeholder = 'something',
        value = 'Can you see me?',
    ], style= {'display': 'none'} # <-- This is the line that will be changed by the dropdown callback

   Output(component_id='element-to-hide', component_property='style'),
   [Input(component_id='dropdown-to-show_or_hide-element', component_property='value')])

def show_hide_element(visibility_state):
    if visibility_state == 'on':
        return {'display': 'block'}
    if visibility_state == 'off':
        return {'display': 'none'}

if __name__ == '__main__':
    app.server.run(debug=False, threaded=True)

Hi @florian.carpente

Your code is OK. But for some reason I can’t understand it doesen’t work properly :thinking:

Take out the style of the dcc.Input (style= {‘display’: ‘none’}) is not necessary because you setted the dropdown to off.

Doing that it works, but I still do not know why :joy:

Hello, Thank you ! But honestly I don’t understand the problem…ahah

1 Like