Python dash.dependencies.Input() Examples

The following are 30 code examples of dash.dependencies.Input(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module dash.dependencies , or try the search function .
Example #1
Source File: dash-dynamic-table-created-without-id.py    From dash-recipes with MIT License 7 votes vote down vote up
def display_output(n_clicks):
    print('display_output ' + str(n_clicks))
    if n_clicks == 0:
        return ''
    return html.Div([
        html.Div([
            dcc.Input(
                value='Input {}'.format(i),
                id='input-{}'.format(i)
            )
            for i in range(10)
        ]),
        dt.DataTable(
            rows=[{'Loading': ''}],
            id='new-table'),
        html.Div(id='dynamic-output')
    ]) 
Example #2
Source File: test_surface_selector.py    From webviz-subsurface with GNU General Public License v3.0 6 votes vote down vote up
def test_surface_selector(dash_duo):

    app = dash.Dash(__name__)
    app.config.suppress_callback_exceptions = True
    realizations = pd.read_csv("tests/data/realizations.csv")
    s = SurfaceSelector(app, surface_context, realizations)

    app.layout = html.Div(children=[s.layout, html.Pre(id="pre", children="ok")])

    @app.callback(Output("pre", "children"), [Input(s.storage_id, "data")])
    def _test(data):
        return json.dumps(json.loads(data))

    dash_duo.start_server(app)

    dash_duo.wait_for_contains_text("#pre", json.dumps(return_value), timeout=4) 
Example #3
Source File: utils.py    From slapdash with MIT License 6 votes vote down vote up
def __init__(self, app, nav_items):
        """Initialise the navbar.

        Params:
        app:        A Dash instance to associate the router with.

        nav_items:  Ordered iterable of navbar items: tuples of `(route, display)`,
                    where `route` is a string corresponding to path of the route
                    (will be prefixed with Dash's 'routes_pathname_prefix') and
                    'display' is a valid value for the `children` keyword argument
                    for a Dash component (ie a Dash Component or a string).
        """
        self.nav_items = nav_items

        @app.callback(
            Output(server.config["NAVBAR_CONTAINER_ID"], "children"),
            [Input(server.config["LOCATION_COMPONENT_ID"], "pathname")],
        )
        def update_nav_callback(pathname):
            """Create the navbar with the current page set to active"""
            if pathname is None:
                # pathname is None on the first load of the app; ignore this
                raise PreventUpdate("Ignoring first Location.pathname callback")
            return self.make_nav(pathname) 
Example #4
Source File: hello.py    From Learning-Object-Oriented-Python with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, app: Dash):
        @app.callback(
            Output('hello_output', 'children'),
            [Input('hello_input', 'value')]
        )

        def update(hello_input: str):
            '''
            Takes in one arguement(s);
            - <hello_input>:   (str)

            Returns a layout_page matching requested pathname.
            '''
            # Some validation
            if len(hello_input) > 2:
                return f'Hello {hello_input}! Welcome to the app!' 
Example #5
Source File: index.py    From webmc3 with Apache License 2.0 6 votes vote down vote up
def add_callbacks(app, trace_info):
    bivariate_layout = bivariate.layout(trace_info)
    univariate_layout = univariate.layout(trace_info)

    @app.callback(
        dep.Output('page-content', 'children'),
        [dep.Input('url', 'pathname')]
    )
    def update_page_content(pathname):
        if pathname in ['/', '/univariate']:
            return univariate_layout
        elif pathname == '/bivariate':
            return bivariate_layout

    bivariate.add_callbacks(app, trace_info)
    univariate.add_callbacks(app, trace_info) 
Example #6
Source File: dash-dynamic-outputs.py    From dash-recipes with MIT License 5 votes vote down vote up
def display_output(value):
    if value == 'Hide':
        return ''
    return html.Div([
        html.Div([
            dcc.Input(value='Input {}'.format(i), id='input-{}'.format(i))
            for i in range(10)
        ]),
        html.Div(id='dynamic-output')
    ]) 
Example #7
Source File: main.py    From deep_architect with MIT License 5 votes vote down vote up
def __init__(self, parent_name, local_name, placeholder_text):
        Component.__init__(self, parent_name, local_name)
        self._register(
            dcc.Input(id=self.full_name,
                      placeholder=placeholder_text,
                      type='text',
                      value='',
                      style={'width': '100%'}))
        # value is an input attribute to read from callbacks. 
Example #8
Source File: callbacks.py    From dash_on_flask with MIT License 5 votes vote down vote up
def register_callbacks(dashapp):
    @dashapp.callback(Output('my-graph', 'figure'), [Input('my-dropdown', 'value')])
    def update_graph(selected_dropdown_value):
        df = pdr.get_data_yahoo(selected_dropdown_value, start=dt(2017, 1, 1), end=dt.now())
        return {
            'data': [{
                'x': df.index,
                'y': df.Close
            }],
            'layout': {'margin': {'l': 40, 'r': 0, 't': 20, 'b': 30}}
        } 
Example #9
Source File: basic-input.py    From dash-docs with MIT License 5 votes vote down vote up
def update_output(input1, input2):
    return u'Input 1 is "{}" and Input 2 is "{}"'.format(input1, input2) 
Example #10
Source File: basic-state.py    From dash-docs with MIT License 5 votes vote down vote up
def update_output(n_clicks, input1, input2):
    return u'''
        The Button has been pressed {} times,
        Input 1 is "{}",
        and Input 2 is "{}"
    '''.format(n_clicks, input1, input2) 
Example #11
Source File: router.py    From Learning-Object-Oriented-Python with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, app: Dash):
        @app.callback(
            Output(
                component_id='page_content',
                component_property='children'
            ),
            [Input(
                component_id='url',
                component_property='pathname'
            )]
        )
        def redirect(pathname):
            '''
            Takes in one arguement(s);
            - <pathname>:   (str)   the url pathname to redirect to

            Returns a layout_page matching requested pathname.
            '''
            if pathname == '/':
                Session['page'] = '/'
                return Layouts.index()

            if pathname == '/hello':
                Session['page'] = '/hello'
                return Layouts.hello()

            # Default if no pathname is matched
            Session['page'] = '/404'
            return Layouts.not_found() 
Example #12
Source File: generate_callbacks.py    From dash-recipes with MIT License 5 votes vote down vote up
def display_output(n_clicks):
    print('display_output ' + str(n_clicks))
    if n_clicks == 0:
        return ''
    return html.Div([
        html.Div([
            dcc.Input(
                value='Input {}'.format(i),
                id='input-{}'.format(i)
            )
            for i in range(10)
        ]),
        html.Div(id='dynamic-output')
    ]) 
Example #13
Source File: common_features.py    From dash-bio with MIT License 5 votes vote down vote up
def user_interactions_callback(
        app,
        dash_duo,
        component_id,
        prop_name
):
    @app.callback(
        dash.dependencies.Output('interaction-results', 'children'),
        [Input(component_id, prop_name)]
    )
    def update_interaction_info(result):
        return json.dumps(result)

    dash_duo.start_server(app)
    dash_duo.wait_for_element('#' + component_id) 
Example #14
Source File: common_features.py    From dash-bio with MIT License 5 votes vote down vote up
def nested_component_layout(
        component
):
    return [
        dcc.Input(id='prop-name'),
        dcc.Input(id='prop-value'),
        html.Div(id='pass-fail-div'),
        html.Button('Submit', id='submit-prop-button'),
        dcc.Graph(
            id='test-graph',
            figure=component
        )
    ] 
Example #15
Source File: common_features.py    From dash-bio with MIT License 5 votes vote down vote up
def simple_app_layout(
        component
):
    return [
        dcc.Input(id='prop-name'),
        dcc.Input(id='prop-value'),
        html.Div(id='pass-fail-div'),
        html.Button('Submit', id='submit-prop-button'),
        component
    ] 
Example #16
Source File: components.py    From webmc3 with Apache License 2.0 5 votes vote down vote up
def add_callbacks(app, trace_info):
    add_include_transformed_callback(app, 'bivariate-x', trace_info)
    add_include_transformed_callback(app, 'bivariate-y', trace_info)

    @app.callback(
        dep.Output('bivariate-scatter', 'figure'),
        [
            dep.Input('bivariate-x-selector', 'value'),
            dep.Input('bivariate-y-selector', 'value')
        ]
    )
    def update_bivariate_scatter(x_varname, y_varname):
        return scatter_figure(trace_info, x_varname, y_varname) 
Example #17
Source File: components.py    From webmc3 with Apache License 2.0 5 votes vote down vote up
def add_include_transformed_callback(app, title, trace):
    @app.callback(
        dep.Output('{}-selector'.format(title), 'options'),
        [dep.Input(
            '{}-selector-include-transformed'.format(title),
            'values'
        )]
    )
    def update_selector_transformed(values):
        return get_varname_options(
            trace,
            include_transformed=values
        ) 
Example #18
Source File: _plugin_abc.py    From webviz-config with MIT License 5 votes vote down vote up
def plugin_data_requested(self) -> Input:
        return Input(self._plugin_wrapper_id, "data_requested") 
Example #19
Source File: _inplace_volumes.py    From webviz-subsurface with GNU General Public License v3.0 5 votes vote down vote up
def vol_callback_inputs(self):
        """Returns all Dash inputs for selecting and filtering volumes
        The number of inputs will vary depending on the available
        selector columns in the volumes dataframe
        """
        inputs = []
        inputs.append(Input(self.ids("response"), "value"))
        inputs.append(Input(self.ids("plot-type"), "value"))
        inputs.append(Input(self.ids("group"), "value"))
        for selector in self.selectors:
            inputs.append(Input(self.selectors_id[selector], "value"))
        return inputs 
Example #20
Source File: _plugin_abc.py    From webviz-config with MIT License 5 votes vote down vote up
def container_data_requested(self) -> Input:
        warnings.warn(
            ("Use 'plugin_data_requested' instead of 'container_data_requested'"),
            DeprecationWarning,
        )
        return self.plugin_data_requested 
Example #21
Source File: _table_plotter.py    From webviz-config with MIT License 5 votes vote down vote up
def plot_input_callbacks(self) -> List[Input]:
        """Creates list of input dependencies for callback
        The inputs are the plot type and the current value
        for each plot option
        """
        inputs = []
        inputs.append(Input(self.uuid("plottype"), "value"))
        for plot_arg in self.plot_args.keys():
            inputs.append(Input(self.uuid(f"dropdown-{plot_arg}"), "value"))
        for filtcol in self.filter_cols:
            inputs.append(Input(self.uuid(f"filter-{filtcol}"), "value"))
        return inputs 
Example #22
Source File: _example_plugin.py    From webviz-config with MIT License 5 votes vote down vote up
def set_callbacks(self, app: Dash) -> None:
        @app.callback(
            Output(self.uuid("output-state"), "children"),
            [Input(self.uuid("submit-button"), "n_clicks")],
        )
        def _update_output(n_clicks: int) -> str:
            return f"Button has been pressed {n_clicks} times." 
Example #23
Source File: test_integration.py    From sd-material-ui with MIT License 5 votes vote down vote up
def test_flat_button(self):
        app = dash.Dash(__name__)

        app.layout = html.Div([
            html.Div(id='waitfor'),
            sd_material_ui.SDFlatButton('test', id='flat-button'),
            html.Div(children=[
                html.Span('num clicks:'),
                html.Span(0, id='test-span-output'),
            ], id='test-output')
        ])

        @app.callback(
            output=Output(component_id='test-span-output', component_property='children'),
            inputs=[Input(component_id='flat-button', component_property='n_clicks')])
        def click_button(n_clicks: int) -> int:
            if n_clicks is not None and n_clicks > 0:
                return n_clicks

        self.startServer(app)

        waiter(self.wait_for_element_by_id)

        self.driver.find_element_by_css_selector('#flat-button button').click()
        self.assertEqual(self.driver.find_element_by_id('test-span-output').text, '1')

        self.driver.find_element_by_css_selector('#flat-button button').click()
        self.assertEqual(self.driver.find_element_by_id('test-span-output').text, '2') 
Example #24
Source File: test_integration.py    From sd-material-ui with MIT License 5 votes vote down vote up
def test_raised_button(self):
        app = dash.Dash(__name__)

        app.layout = html.Div([
            html.Div(id='waitfor'),
            sd_material_ui.SDRaisedButton('test', id='raised-button'),
            html.Div(children=[
                html.Span('num clicks:'),
                html.Span(0, id='test-span-output'),
            ], id='test-output')
        ])

        @app.callback(
            output=Output(component_id='test-span-output', component_property='children'),
            inputs=[Input(component_id='raised-button', component_property='n_clicks')])
        def click_button(n_clicks: int) -> int:
            if n_clicks is not None and n_clicks > 0:
                return n_clicks

        self.startServer(app)

        waiter(self.wait_for_element_by_id)

        self.driver.find_element_by_css_selector('#raised-button button').click()
        self.assertEqual(self.driver.find_element_by_id('test-span-output').text, '1')

        self.driver.find_element_by_css_selector('#raised-button button').click()
        self.assertEqual(self.driver.find_element_by_id('test-span-output').text, '2') 
Example #25
Source File: _well_cross_section_fmu.py    From webviz-subsurface with GNU General Public License v3.0 5 votes vote down vote up
def intersection_option(self):
        options = [
            {"label": "Keep zoom state", "value": "keep_zoom_state"},
            {"label": "Show surface fill", "value": "show_surface_fill"},
        ]
        value = ["show_surface_fill"]
        if self.segyfiles:
            options.append({"label": "Show seismic", "value": "show_seismic"})
        if self.zonelog is not None:
            options.append({"label": "Show zonelog", "value": "show_zonelog"})
            value.append("show_zonelog")

        return html.Div(
            style=self.set_style(marginTop="20px"),
            children=[
                html.Label("Intersection settings", style={"font-weight": "bold"}),
                html.Label("Sampling"),
                dcc.Input(
                    id=self.ids("sampling"),
                    debounce=True,
                    type="number",
                    value=self.sampling,
                ),
                html.Label("Extension"),
                dcc.Input(
                    id=self.ids("nextend"),
                    debounce=True,
                    type="number",
                    value=self.nextend,
                ),
                dcc.Checklist(id=self.ids("options"), options=options, value=value),
            ],
        ) 
Example #26
Source File: main.py    From deep_architect with MIT License 5 votes vote down vote up
def get_input(self, attribute_name):
        return Input(self.full_name, attribute_name) 
Example #27
Source File: _parameter_response_correlation.py    From webviz-subsurface with GNU General Public License v3.0 5 votes vote down vote up
def correlation_input_callbacks(self):
        """List of Inputs for correlation callback"""
        callbacks = [
            Input(self.ids("ensemble"), "value"),
            Input(self.ids("responses"), "value"),
        ]
        if self.response_filters:
            for col_name in self.response_filters:
                callbacks.append(Input(self.ids(f"filter-{col_name}"), "value"))
        return callbacks 
Example #28
Source File: _parameter_response_correlation.py    From webviz-subsurface with GNU General Public License v3.0 5 votes vote down vote up
def distribution_input_callbacks(self):
        """List of Inputs for distribution callback"""
        callbacks = [
            Input(self.ids("correlation-graph"), "clickData"),
            Input(self.ids("initial-parameter"), "data"),
            Input(self.ids("ensemble"), "value"),
            Input(self.ids("responses"), "value"),
        ]
        if self.response_filters:
            for col_name in self.response_filters:
                callbacks.append(Input(self.ids(f"filter-{col_name}"), "value"))
        return callbacks 
Example #29
Source File: _morris_plot.py    From webviz-subsurface with GNU General Public License v3.0 5 votes vote down vote up
def set_callbacks(self, app):
        @app.callback(
            [
                Output(self.graph_id, "output"),
                Output(self.graph_id, "parameter"),
                Output(self.graph_id, "parameters"),
            ],
            [Input(self.vector_id, "value")],
        )
        def _update_plot(vector):
            df = self.data[self.data["name"] == vector]
            df = df.sort_values("time")
            output = (
                df[["mean", "max", "min", "time"]]
                .drop_duplicates()
                .to_dict(orient="records")
            )
            parameters = []

            for name in self.data["name"].unique():
                if name != vector:
                    name_df = self.data[self.data["name"] == name]
                    parameters.append(
                        {
                            "main": list(name_df["morris_main"]),
                            "name": str(name),
                            "interactions": list(name_df["morris_interaction"]),
                        }
                    )
            return output, vector, parameters 
Example #30
Source File: _well_cross_section.py    From webviz-subsurface with GNU General Public License v3.0 5 votes vote down vote up
def well_options(self):
        return html.Div(
            style={"marginLeft": "20px", "marginRight": "0px", "marginBotton": "0px"},
            children=[
                html.Div(
                    children=html.Label(
                        children=[
                            html.Span("Sampling:", style={"font-weight": "bold"}),
                            dcc.Input(
                                id=self.ids("sampling"),
                                debounce=True,
                                type="number",
                                value=self.sampling,
                            ),
                        ]
                    )
                ),
                html.Div(
                    children=html.Label(
                        children=[
                            html.Span("Nextend:", style={"font-weight": "bold"}),
                            dcc.Input(
                                id=self.ids("nextend"),
                                debounce=True,
                                type="number",
                                value=self.nextend,
                            ),
                        ]
                    )
                ),
            ],
        )