def make_left_panel(split=True, upper_value='Kinematics', lower_value='Kinematics'): """Helper to make the left graph panels. If split=True, make two stacked panels""" # the upper graph & dropdown items = [ dcc.Dropdown( id='dd-vars-upper-multi', clearable=False, options=opts_multi, value=upper_value, ), html.Div( id='div-upper', style={'height': '50%'} if split else {'height': '100%'} ), ] if split: # add the lower one items.extend( [ dcc.Dropdown( id='dd-vars-lower-multi', clearable=False, options=opts_multi, value=lower_value, ), html.Div(id='div-lower', style={'height': '50%'}), ] ) return html.Div(items, style={'height': '80vh'})
def map_layout(self) -> wcc.FlexBox: return wcc.FlexBox(children=[ dcc.Dropdown( id=self.ids("surface-name"), options=[{ "label": name, "value": name } for name in self.surfacenames], value=self.surfacenames[0], clearable=False, multi=False, persistence=True, persistence_type="session", ), dcc.Dropdown( id=self.ids("surface-type"), options=[{ "label": name, "value": name } for name in [ "stddev", "mean", "p10", "p90", "minimum", "maximum", ]], value="stddev", clearable=False, multi=False, persistence=True, persistence_type="session", ), ], )
def get_form(self): print("self.project : ", self.project) project_input = dbc.Form( [ dbc.Label("Project", html_for="Test_Case_Project_ID"), dcc.Dropdown(id="Test_Case_Project_ID", options=[{'label': self.project, 'value': self.project}], value=self.project, multi=False), ] ) api_input = dbc.Form( [ dbc.Label("API", html_for="Test_Case_API_ID"), dbc.Input(type="text", id="Test_Case_API_ID", placeholder="Enter the API"), ] ) method_input = dbc.Form( [ dbc.Label("Method", html_for="Test_Case_Method_ID"), dcc.Dropdown(id="Test_Case_Method_ID", options=[{'label': x, 'value': x} for x in methods], multi=False), ] ) body_input = dbc.Form( [ dbc.Label("Body : JSON", html_for="Test_Case_Body_ID"), dcc.Textarea(id="Test_Case_Body_ID", style={"width": "100%"}), ] ) form = dbc.Form([project_input, api_input, method_input, body_input]) return form
def main(unused_argv): # TODO: Make this a more efficient query. sessions = queries.GetSessions() points_columns = queries.GetPointsColumns() + [ 'front_brake_pressure_percentage', 'rear_brake_pressure_percentage', 'racing_line', 'gsum', 'time_delta' ] tracks = queries.GetTracks() app.layout = html.Div( style={'display': 'grid'}, children=[ dcc.Location(id='url', refresh=False), dcc.Link('Home', href='/'), dcc.Link('Clear', href='/track=None&points=None'), dcc.Dropdown( id='track-dropdown', options=[{ 'label': i, 'value': i } for i in tracks], searchable=False, clearable=False, style={'width': '50%'}, ), dcc.Dropdown( id='points-dropdown', options=[{ 'label': i, 'value': i } for i in points_columns], clearable=False, multi=True, ), dash_table.DataTable( id='sessions-table', columns=[{ 'name': i, 'id': i } for i in sessions.columns], filter_action='native', sort_action='native', sort_mode='single', sort_by=[{ 'column_id': 'lap_time', 'direction': 'asc' }, { 'column_id': 'session_time', 'direction': 'desc' }], row_selectable='multi', page_action='native', page_current=0, page_size=10, ), html.Div(id='graphs'), ], ) app.run_server(host='0.0.0.0', debug=FLAGS.debug)
def make_scatter_menu(id_index): #, colnames, current_options): print('** make_scatter_menu') return dbc.Offcanvas( [html.P("Dropdowns for setting data input, X, Y, color, size:"), dbc.Row([dbc.Col('Title:'), dbc.Col(dcc.Input(id={'type': 'scatter_inputtext', 'index': id_index, 'property': 'title'}, placeholder='Enter title here', #value=''), ), width=7)], justify='start'), dbc.Row([dbc.Col('Data:'), dbc.Col(dcc.Dropdown(id={'type': 'scatter_dropdown', 'index': id_index, 'property': 'dataset'}, #options=[dict(label='Lifehistory', value='Lifehistory'), # dict(label='Load file...', value='_load_file')], #value='Lifehistory' ), width=7)], justify='start'), dbc.Row([dbc.Col('X:'), dbc.Col(dcc.Dropdown(id={'type': 'scatter_dropdown', 'index': id_index, 'property': 'x'}, ), #options=[{'label': c, 'value': c} for c in df_records[0].keys()], #value='logAdultWeight'), width=7)], justify='start'), dbc.Row([dbc.Col('Y:'), dbc.Col(dcc.Dropdown(id={'type': 'scatter_dropdown', 'index': id_index, 'property': 'y'},), #options=[{'label': c, 'value': c} for c in df_records[0].keys()], #value='MaxLifespan'), width=7)], justify='start'), # dbc.Row([dbc.Col('Color:'), # dbc.Col(dcc.Dropdown(id={'type':'scatter_dropdown', 'index':id_index, 'property':'color'}, # options=[{'label': c, 'value': c} for c in df.columns]), # width=7)], # justify='start'), # # dbc.Row([dbc.Col('Size:'), # dbc.Col(dcc.Dropdown(id={'type':'scatter_dropdown', 'index':id_index, 'property':'size'}, # options=[{'label': c, 'value': c} for c in df.columns]), # width=7)], # justify='start'), dbc.Row(dbc.Col(' ')), dbc.Row(dbc.Col( dbc.Button("Apply", size="sm", n_clicks=0, id={'type': 'scatter_configure_ok', 'index': id_index}), class_name="g-2")) ], title="Menu: Scatter item", is_open=False, id={'type': 'scatter_menu', 'index': id_index} )
def get_layout(**kwargs): return html.Div([ dcc.Markdown( dedent(""" # Research Analysis """)), dcc.Dropdown(id="app-option", options=[{ 'label': i, 'value': i } for i in get_app_options()], value=get_app_options()[0]), dcc.Dropdown(id="balance-option", options=[{ 'label': i, 'value': i } for i in get_balancing_options()], value="Combined"), dcc.Loading(id="loading-icon", type="circle", children=[ html.Div( children=[dcc.Graph(id="latency_vs_price")], style={'margin': 'auto'}, ), ]), dcc.Loading(id="loading-icon", type="circle", children=[ html.Div(dcc.Graph(id="price_cdf_koss_weights")), ]), dcc.Loading(id="loading-icon", type="circle", children=[ html.Div(dcc.Graph(id="price_cdf_algo_comparison")), ]), dcc.Loading(id="loading-icon", type="circle", children=[ html.Div(dcc.Graph(id="latency_cdf_koss_weights")), ]), dcc.Loading(id="loading-icon", type="circle", children=[ html.Div(dcc.Graph(id="latency_cdf_algo_comparison")), ]), # dcc.Loading( # id = "loading-icon", # type="circle", # children=[html.Div(dcc.Graph(id="latecy-to-price-graph"))] # ), ])
def selection(): """ Drop downs for Comparison tab """ selection_health = [ html.Br(), dbc.Row([ dbc.Col([ 'Group by:', dbc.Card( dcc.Dropdown( style={'height': '40px'}, id='group', options=[{'label': 'Patient', 'value': 'Name'}, {'label': 'Age', 'value': 'Age'}, {'label': 'Sex', 'value': 'Sex'}], value='Name', clearable=False ))], style={'height': '100%'}), dbc.Col([ 'First plot(x axis)', dbc.Card( dcc.Dropdown( id='Bar chart', style={'height': '100%'}, options=[{'label': name, 'value': name} for name in label_bar], value=label_bar[0], clearable=False, ))]), dbc.Col([ 'Second plot(y axis)', dbc.Card(dcc.Dropdown( id='linear plot', style={'height': '100%'}, options=[{'label': name, 'value': name} for name in label_linear], value=label_linear[1], clearable=False, ))]), ]), ] selection_workout = [html.Br(), dbc.Row([dbc.Col(['Show heart rate during', dcc.Dropdown( id='Bar chart2', style={'height': '100%'}, options=[{'label': name, 'value': name} for name in label_bar2], value='Walking', clearable=False, )])])] return selection_health, selection_workout
def test_cbmt010_shared_grandparent(dash_duo): app = Dash(__name__) app.layout = html.Div( [ html.Div("id", id="session-id"), dcc.Dropdown(id="dropdown-1"), dcc.Dropdown(id="dropdown-2"), html.Div(id="output"), ] ) options = [{"value": "a", "label": "a"}] call_counts = {"dropdown_1": Value("i", 0), "dropdown_2": Value("i", 0)} @app.callback( Output("dropdown-1", "options"), [Input("dropdown-1", "value"), Input("session-id", "children")], ) def dropdown_1(value, session_id): call_counts["dropdown_1"].value += 1 return options @app.callback( Output("dropdown-2", "options"), Input("dropdown-2", "value"), Input("session-id", "children"), ) def dropdown_2(value, session_id): call_counts["dropdown_2"].value += 1 return options @app.callback( Output("output", "children"), Input("dropdown-1", "value"), Input("dropdown-2", "value"), ) def set_output(v1, v2): return (v1 or "b") + (v2 or "b") dash_duo.start_server(app) dash_duo.wait_for_text_to_equal("#output", "bb") assert call_counts["dropdown_1"].value == 1 assert call_counts["dropdown_2"].value == 1 assert not dash_duo.get_logs()
def test_dddo001_dynamic_options(dash_dcc): dropdown_options = [ { "label": "New York City", "value": "NYC" }, { "label": "Montreal", "value": "MTL" }, { "label": "San Francisco", "value": "SF" }, ] app = Dash(__name__) app.layout = dcc.Dropdown(id="my-dynamic-dropdown", options=[]) @app.callback( Output("my-dynamic-dropdown", "options"), [Input("my-dynamic-dropdown", "search_value")], ) def update_options(search_value): if not search_value: raise PreventUpdate return [o for o in dropdown_options if search_value in o["label"]] dash_dcc.start_server(app) # Get the inner input used for search value. dropdown = dash_dcc.find_element("#my-dynamic-dropdown") input_ = dropdown.find_element_by_css_selector("input") # Focus on the input to open the options menu input_.send_keys("x") # No options to be found with `x` in them, should show the empty message. dash_dcc.wait_for_text_to_equal(".Select-noresults", "No results found") input_.clear() input_.send_keys("o") options = dropdown.find_elements_by_css_selector( ".VirtualizedSelectOption") # Should show all options. assert len(options) == 3 # Searching for `on` input_.send_keys("n") options = dropdown.find_elements_by_css_selector( ".VirtualizedSelectOption") assert len(options) == 1 print(options) assert options[0].text == "Montreal" assert dash_dcc.get_logs() == []
def _sub_layouts(self): layouts = super()._sub_layouts all_transformations = html.Div([ transformation.container_layout() for name, transformation in self.transformations.items() ]) choices = dcc.Dropdown( options=[{ "label": transformation.title, "value": name } for name, transformation in self.transformations.items()], multi=True, value=[], placeholder="Select one or more transformations...", id=self.id("choices"), style={"max-width": "65vmin"}, persistence=True, ) layouts.update({ "all_transformations": all_transformations, "choices": choices }) return layouts
def layout(self) -> html.Div: return html.Div( id=self.ids("layout"), children=[ html.Span("Parameter distribution:", style={"font-weight": "bold"}), html.Div( style=self.set_grid_layout("8fr 1fr 2fr"), children=[ dcc.Dropdown( id=self.ids("parameter"), options=[{ "value": col, "label": col } for col in self.parameter_columns], value=self.parameter_columns[0], clearable=False, persistence=True, persistence_type="session", ), self.make_buttons(self.ids("prev-btn"), self.ids("next-btn")), ], ), wsc.PriorPosteriorDistribution(id=self.ids("graph")), ], )
def attribute_selector(self): return html.Div( style={"display": "grid"}, children=[ html.Label("Surface attribute", style={ "fontSize": 15, "fontWeight": "bold" }), html.Div( style=self.set_grid_layout("6fr 1fr"), children=[ dcc.Dropdown( id=self.attr_id, options=[{ "label": attr, "value": attr } for attr in self.attrs], value=self.current_selections["attribute"], clearable=False, persistence=True, persistence_type="session", style={ "fontSize": 15, "fontWeight": "normal" }, ), self._make_buttons(self.attr_id_btn_prev, self.attr_id_btn_next), ], ), ], )
def _sub_layouts(self): search = html.Div(self._make_search_box(), id=self.id("search_container")) random_link = html.A("get random mp-id", className="is-text is-size-7", id=self.id("random")) dropdown = dcc.Dropdown(id=self.id("dropdown"), clearable=False) dropdown_container = html.Div( [ html.Label("Multiple results found, please select one:"), dropdown ], id=self.id("dropdown-container"), style={"display": "none"}, ) warning = html.Div(style={"display": "none"}, id=self.id("warning")) search = html.Div([search, random_link], style={"marginBottom": "0.75rem"}) search = html.Div([search, warning, dropdown_container]) return {"search": search}
def test_ddro002_remove_option_multi(dash_dcc): dropdown_options = sample_dropdown_options app = Dash(__name__) value = ["MTL", "SF"] app.layout = html.Div([ dcc.Dropdown( options=dropdown_options, value=value, multi=True, id="dropdown", ), html.Button("Remove option", id="remove"), html.Div(id="value-output"), ]) @app.callback(Output("dropdown", "options"), [Input("remove", "n_clicks")]) def on_click(n_clicks): if not n_clicks: raise PreventUpdate return sample_dropdown_options[:-1] @app.callback(Output("value-output", "children"), [Input("dropdown", "value")]) def on_change(val): return json.dumps(val) dash_dcc.start_server(app) btn = dash_dcc.wait_for_element("#remove") btn.click() dash_dcc.wait_for_text_to_equal("#value-output", '["MTL"]')
def attribute_selector(self) -> html.Div: return html.Div( style={"display": "grid"}, children=[ html.Label("Surface attribute"), html.Div( style=self.set_grid_layout("6fr 1fr"), children=[ dcc.Dropdown( id=self.attr_id, options=[{ "label": attr, "value": attr } for attr in self.attrs], value=self.attrs[0], clearable=False, persistence=True, persistence_type="session", ), self._make_buttons(self.attr_id_btn_prev, self.attr_id_btn_next), ], ), ], )
def selector(self, wrapper_id, dropdown_id, title, default_value, btn_prev, btn_next): return html.Div( id=wrapper_id, style={"display": "none"}, children=[ html.Label(title, style={ "fontSize": 15, "fontWeight": "bold" }), html.Div( style=self.set_grid_layout("6fr 1fr"), children=[ dcc.Dropdown( id=dropdown_id, value=default_value, clearable=False, persistence=True, persistence_type="session", style={ "fontSize": 15, "fontWeight": "normal" }, ), self._make_buttons(btn_prev, btn_next), ], ), ], )
def selector( self, wrapper_id: str, dropdown_id: str, title: str, btn_prev: str, btn_next: str, ) -> html.Div: return html.Div( id=wrapper_id, style={"display": "none"}, children=[ html.Label(title), html.Div( style=self.set_grid_layout("6fr 1fr"), children=[ dcc.Dropdown( id=dropdown_id, clearable=False, persistence=True, persistence_type="session", ), self._make_buttons(btn_prev, btn_next), ], ), ], )
def test_cbsc006_array_of_objects(dash_duo, engine): with json_engine(engine): app = Dash() app.layout = html.Div( [html.Button(id="btn"), dcc.Dropdown(id="dd"), html.Div(id="out")]) @app.callback(Output("dd", "options"), [Input("btn", "n_clicks")]) def set_options(n): return [{ "label": "opt{}".format(i), "value": i } for i in range(n or 0)] @app.callback(Output("out", "children"), [Input("dd", "options")]) def set_out(opts): print(repr(opts)) return len(opts) dash_duo.start_server(app) dash_duo.wait_for_text_to_equal("#out", "0") for i in range(5): dash_duo.find_element("#btn").click() dash_duo.wait_for_text_to_equal("#out", str(i + 1)) dash_duo.select_dcc_dropdown("#dd", "opt{}".format(i))
def plot_options_layout(self) -> wcc.FlexBox: """Row layout of dropdowns for plot options""" return wcc.FlexBox(children=[ html.Div(children=html.Label(children=[ html.Span("Response:", style={"font-weight": "bold"}), dcc.Dropdown( id=self.ids("response"), options=[{ "label": volume_description(i), "value": i } for i in self.responses], value=self.initial_response if self.initial_response in self.responses else self.responses[0], clearable=False, persistence=True, persistence_type="session", ), ])), html.Div(children=html.Label(children=[ html.Span("Plot type:", style={"font-weight": "bold"}), dcc.Dropdown( id=self.ids("plot-type"), options=[{ "label": i, "value": i } for i in self.plot_types], value=self.initial_plot, clearable=False, persistence=True, persistence_type="session", ), ])), html.Div(children=html.Label(children=[ html.Span("Group by:", style={"font-weight": "bold"}), dcc.Dropdown( id=self.ids("group"), options=[{ "label": i.lower().capitalize(), "value": i } for i in self.selectors], value=self.initial_group, placeholder="Not grouped", persistence=True, persistence_type="session", ), ])), ], )
def NamedDropdown(name, **kwargs): return html.Div( style={"margin": "10px 0px"}, children=[ html.P(children=f"{name}", style={"margin-left": "3px"}), dcc.Dropdown(**kwargs), ], )
def getMasthead(): return html.Div([ html.Div( dcc.Dropdown(id='discipline-selection', options=[{'label': i, 'value': i} for i in disciplines], value='Batting', placeholder='Choose Discipline...'), className='masthead__column_1', id='discipline-selection-div' ), html.Div( dcc.Dropdown( id='season-selection', options=[{'label': i, 'value': i} for i in seasons], value='2021', placeholder='Choose Season...' ), className='masthead__column_2', id='season-selection-div' ), html.Div( dcc.Dropdown( id='match-type-selection', options=[{'label': i, 'value': i} for i in match_types], value='All', clearable=False ), className='masthead__column_3', id='match-type-selection-div' ), html.Div( dcc.Dropdown( id='inter-tav-selection', options=[{'label': i, 'value': i} for i in inter_tav_types], value='Railway Taverners CC', clearable=False, placeholder='Choose Match Type...' ), className='masthead__column_4', id='inter-tav-selection-div' ), ], id='masthead-div', className='hidden-grid l-grid')
def test_dddo003_value_no_options(dash_dcc): app = Dash(__name__) app.layout = html.Div([ dcc.Dropdown(value="foobar", id="dropdown"), ]) dash_dcc.start_server(app) assert dash_dcc.get_logs() == [] dash_dcc.wait_for_element("#dropdown")
def dropdown_key_y(): return html.Div([ dcc.Dropdown( id='mespolar_dropdown_key_y', options=[i for i in keys()], placeholder="Y axis", value=None ) ], style={'width': '20%', 'display': 'inline-block'} )
def make_plot_control(id_, label, params, default): return dbc.Row([ html.Label(label), dcc.Dropdown(id=id_, options=params, value=default, multi=False, clearable=False, style={"color": "black"}) ], justify="center")
def map_view_layout(self) -> html.Div: return html.Div(children=[ wcc.FlexBox(children=[ html.Div(children=[ html.Label( style={ "font-weight": "bold", "textAlign": "center", }, children="Select surface", ), dcc.Dropdown( id=self.ids("map-dropdown"), options=[{ "label": name, "value": name } for name in self.surfacenames], value=self.surfacenames[0], clearable=False, persistence=True, persistence_type="session", ), ]), ], ), html.Div( style={ "marginTop": "0px", "height": "800px", "zIndex": -9999, }, children=[ webviz_subsurface_components.LeafletMap( id=self.ids("layered-map"), layers=[], unitScale={}, autoScaleMap=True, minZoom=-19, drawTools={ "drawMarker": False, "drawPolygon": False, "drawPolyline": True, "position": "topright", }, switch={ "value": False, "disabled": False, "label": "Hillshading", }, mouseCoords={"position": "bottomright"}, colorBar={"position": "bottomright"}, ), ], ), ])
def LabeledDropdown(label, id, help_text='', max_width=400, **kwargs): """'max_width' specifies the maximum width of the Div containing all of these components. """ return html.Div(className='labeled-comp', id=f'div-{id}', style={'maxWidth': max_width}, children=[ make_label(label, id, help_text), dcc.Dropdown(id=id, **kwargs) ])
def marginal_log_layout(self) -> html.Div: if self.marginal_logs is not None: return html.Div(children=html.Label(children=[ html.Span("Marginal log:", style={"font-weight": "bold"}), dcc.Dropdown( id=self.ids("marginal-log"), options=[{ "label": log, "value": log } for log in self.marginal_logs], placeholder="Display log", clearable=True, persistence=True, persistence_type="session", ), ]), ) return html.Div( style={"visibility": "hidden"}, children=dcc.Dropdown(id=self.ids("marginal-log"), persistence=True), )
def render_page(url): return [ dcc.Dropdown( id="my-dropdown", options=[ {"label": "option 1", "value": "1"}, {"label": "option 2", "value": "2"}, ], value="1", ), dcc.Graph(id="my-graph"), ]
def test_cbmt011_callbacks_triggered_on_generated_output(dash_duo): app = Dash(__name__, suppress_callback_exceptions=True) call_counts = {"tab1": Value("i", 0), "tab2": Value("i", 0)} app.layout = html.Div( [ dcc.Dropdown( id="outer-controls", options=[{"label": i, "value": i} for i in ["a", "b"]], value="a", ), dcc.RadioItems( options=[ {"label": "Tab 1", "value": 1}, {"label": "Tab 2", "value": 2}, ], value=1, id="tabs", ), html.Div(id="tab-output"), ] ) @app.callback(Output("tab-output", "children"), Input("tabs", "value")) def display_content(value): return html.Div([html.Div(id="tab-{}-output".format(value))]) @app.callback(Output("tab-1-output", "children"), Input("outer-controls", "value")) def display_tab1_output(value): call_counts["tab1"].value += 1 return 'Selected "{}" in tab 1'.format(value) @app.callback(Output("tab-2-output", "children"), Input("outer-controls", "value")) def display_tab2_output(value): call_counts["tab2"].value += 1 return 'Selected "{}" in tab 2'.format(value) dash_duo.start_server(app) dash_duo.wait_for_text_to_equal("#tab-output", 'Selected "a" in tab 1') dash_duo.wait_for_text_to_equal("#tab-1-output", 'Selected "a" in tab 1') assert call_counts["tab1"].value == 1 assert call_counts["tab2"].value == 0 dash_duo.find_elements('input[type="radio"]')[1].click() dash_duo.wait_for_text_to_equal("#tab-output", 'Selected "a" in tab 2') dash_duo.wait_for_text_to_equal("#tab-2-output", 'Selected "a" in tab 2') assert call_counts["tab1"].value == 1 assert call_counts["tab2"].value == 1 assert not dash_duo.get_logs()
def get_param_dash_component(param_key, param_set): """ Converts param_key:iterable (param_set) into a list of dash dropdowns """ if isinstance(param_set, set) or isinstance(param_set, list): dropdown_options = [{ "label": param, "value": param } for param in param_set] return dcc.Dropdown(options=dropdown_options, placeholder=param_key) else: return []