def init_dash(server): dash_app = dash.Dash( __name__, server=server, routes_pathname_prefix='/charts/', external_stylesheets=[ dbc.themes.BOOTSTRAP, '../static/css/dash_style.css', ] ) dash_app.title = 'Charts' dash_app.layout = html.Div( children=[ html.Div( children=[ html.Div( className="m-2", children=[dbc.Select( id='pair', value='BTCUSD', options=[{"label": str(x).upper(), "value": str(x).upper()} for x in unique_pairs], )]), html.Div( className="m-2", children=[dbc.Select( id='interval', value=15, options=[ {"label": '1m', "value": 1}, {"label": '3m', "value": 3}, {"label": '5m', "value": 5}, {"label": '15m', "value": 15}, {"label": '30m', "value": 30}, {"label": '1h', "value": 60}, {"label": '2h', "value": 60 * 2}, {"label": '3h', "value": 60 * 3}, {"label": '4h', "value": 60 * 4}, {"label": '6h', "value": 60 * 6}, {"label": '12h', "value": 60 * 12}, {"label": '1d', "value": 60 * 24}, ] )] )], style={"display": "flex", "flexWrap": "wrap"}), dcc.Graph(id='chart') ], style={"height": "100vh"}) init_dash_callbacks(dash_app)
def generate_model_dropdown( self, dropdown_number ): """ Utility function to generate a dropdown component which allows the user to choose between different topic models. """ model_options = [] for i, meta in enumerate(self.all_metadata): model_options.append( { "label":meta["id"], "value":str(i) } ) component_id = "compare-model-dropdown%d" % dropdown_number if len(model_options) > dropdown_number-1: return dbc.Select( id=component_id, options=model_options, value=str(self.current_metadata_indices[dropdown_number-1]) ) return dbc.Select(id=component_id, options=model_options )
def generate_embedding_dropdown(self): """ Utility function to generate a dropdown component which allows the user to choose between different word embedding models. """ embed_options = [] for embed_id in self.webcore.get_embedding_ids(): em = self.webcore.get_embedding_metadata(embed_id) if em is None: continue label = "%s (%s)" % (embed_id, em["description"]) embed_options.append({"label": label, "value": embed_id}) if len(embed_options) > 0: return dbc.Select(id='embed-dropdown', options=embed_options, value=embed_options[0]["value"]) return dbc.Select(id='embed-dropdown', options=embed_options)
def HalfSquareSelector(idx, options, value): return dbc.InputGroup( [ dbc.InputGroupAddon("Map {}".format(idx), addon_type="prepend"), dbc.Select(id={'type': 'halfsquare-select', 'index': idx}, options=options, value=value) ] )
def TrackLayoutSelector(idx, options, value): return dbc.InputGroup( [ dbc.InputGroupAddon("Track {}".format(idx), addon_type="prepend"), dbc.Select(id={'type': 'track-select'.format(idx), 'index': idx}, options=options, value=value) ] )
def set_data_shown(): return dbc.Select( options=[ { "label": "Cases Total", "value": "Cases Total" }, { "label": "Daily Peak", "value": "Daily Peak" }, { "label": "New Cases", "value": "New Cases" }, { "label": "Active Cases", "value": "Active Cases" }, { "label": "Deaths", "value": "Deaths" }, { "label": "Recovered Total", "value": "Recovered Total" }, ], value="Cases Total", id="select-set-data-shown", )
def PaletteSelector(dataset, options, value): index = [x.value for x in PaletteDefaultLayout].index(dataset.encode()) return dbc.InputGroup([ dbc.InputGroupAddon(UserReadableTrackNames.__getattr__(dataset).value, addon_type="prepend"), dbc.Select(id={'type': 'colorpalette-select', 'index': index}, options=options, value=value) ])
def _make_selector(options: dict, month: int, year: int) -> dbc.Select: _this_year = datetime.now().year c = calendar.month_name next_year = [{ "label": options['next_year'], "value": f"1 {options['next_year'][0]}" }] # Jan (1) Year next_months = [{ "label": f"{c[m]} {_this_year}", "value": f"{m} {_this_year}" } for m in options['next_months']] # Months Year today = [{ "label": "Today", "value": f"{options['today'][0]} {_this_year}", 'active': True }] # Month Year prev_months = [{ "label": f"{c[m]} {_this_year}", "value": f"{m} {_this_year}" } for m in options['prev_months']] # Months Year prev_years = [{ "label": y, "value": f"1 {y}" } for y in options['prev_years']] # Jan (1) Year selector = dbc.Select( id="calendar_month_selector", placeholder=f"{c[month]}, {year}", options=(next_year + next_months + today + prev_months + prev_years), persistence=True, ) return selector
def layout(self): return dbc.Card([ make_hideable(dbc.CardHeader([ html.Div([ html.H3(self.title, id='decisiontrees-title-' + self.name), make_hideable(html.H6(self.subtitle, className='card-subtitle'), hide=self.hide_subtitle), dbc.Tooltip(self.description, target='decisiontrees-title-' + self.name), ]), ]), hide=self.hide_title), dbc.CardBody([ dbc.Row([ make_hideable(dbc.Col([ dbc.Label(f"{self.explainer.index_name}:", id='decisiontrees-index-label-' + self.name), dbc.Tooltip( f"Select {self.explainer.index_name} to display decision trees for", target='decisiontrees-index-label-' + self.name), self.index_selector.layout() ], md=4), hide=self.hide_index), make_hideable(dbc.Col([ dbc.Label("Highlight tree:", id='decisiontrees-tree-label-' + self.name), dbc.Tooltip( f"Select a specific tree to highlight. You can also " "highlight by clicking on a specifc bar in the bar chart.", target='decisiontrees-tree-label-' + self.name), dbc.Select( id='decisiontrees-highlight-' + self.name, options=[{ 'label': str(tree), 'value': tree } for tree in range(self.explainer.no_of_trees)], value=self.highlight) ], md=2), hide=self.hide_highlight), make_hideable(dbc.Col([self.selector.layout()], width=2), hide=self.hide_selector) ]), dbc.Row([ dbc.Col([ dcc.Graph(id="decisiontrees-graph-" + self.name, config=dict(modeBarButtons=[['toImage']], displaylogo=False)), ]) ]), dbc.Row([ make_hideable(dbc.Col( [self.popout.layout()], md=2, align="start"), hide=self.hide_popout), ], justify="end"), ]) ])
def params_line(e): data = params_dict[e] if data['element'] == 'input': if 'step' in data: return dbc.InputGroup([ dbc.InputGroupText(e, className='par-input-text no-border'), dbc.Input(id=f'par_{e}', type=data['type'], step=data['step'], className='par-input-field no-border') ], className='no-border') else: return dbc.InputGroup([ dbc.InputGroupText(e, className='par-input-text no-border'), dbc.Input(id=f'par_{e}', type=data['type'], className='par-input-field no-border') ], className='no-border') else: return dbc.InputGroup([ dbc.InputGroupText(e, className='par-input-text no-border'), dbc.Select(id=f'par_{e}', options=opt_list(data['options']), className='par-select-field no-border') ], className='no-border')
def get_candidate_select(): dropdown_style = {"padding": "4px", "maxWidth": "90%", "margin": "auto"} dropdown = html.Div( [dbc.Select(id="candidate-select", value="all")], style=dropdown_style, ) return dropdown
def chartlayout(): return html.Div([ dbc.Row( [ dbc.Col(dbc.Button('Add Subplot', id='add-sub', color='primary', outline=True, block=True), md=3), dbc.Col(dbc.Button('Remove Subplot', id='rm-sub', color='primary', outline=True, block=True), md=3), dbc.Col(dbc.Select( id='n-column', options=[ { 'label': 'One Column', 'value': 1 }, { 'label': 'Two Columns', 'value': 2 }, { 'label': 'Three Columns', 'value': 3 }, { 'label': 'Four Columns', 'value': 4 }, { 'label': 'Six Columns', 'value': 6 }, ], value=1, ), md=3), dbc.Col(dbc.Button('Load Data', id='load-data', color='primary', outline=True, block=True), md=3), ], no_gutters=False, align='center', justify='center', form=True, ), html.Div(id='chart-area', className='row mt-2', children=[subplot()]), html.Div(1, id='nplot', style={'display': 'none'}) ])
def layout(self): return dbc.Card([ make_hideable(dbc.CardHeader([ html.Div([ html.H3(self.title, id='decisionpath-table-title-' + self.name), make_hideable(html.H6(self.subtitle, className='card-subtitle'), hide=self.hide_subtitle), dbc.Tooltip(self.description, target='decisionpath-table-title-' + self.name), ]), ]), hide=self.hide_title), dbc.CardBody([ dbc.Row([ make_hideable(dbc.Col([ dbc.Label( f"{self.explainer.index_name}:", id='decisionpath-table-index-label-' + self.name), dbc.Tooltip( f"Select {self.explainer.index_name} to display decision tree for", target='decisionpath-table-index-label-' + self.name), self.index_selector.layout() ], md=4), hide=self.hide_index), make_hideable(dbc.Col([ dbc.Label( "Show tree:", id='decisionpath-table-tree-label-' + self.name), dbc.Tooltip( f"Select decision tree to display decision tree path for", target='decisionpath-table-tree-label-' + self.name), dbc.Select( id='decisionpath-table-highlight-' + self.name, options=[{ 'label': str(tree), 'value': tree } for tree in range(self.explainer.no_of_trees)], value=self.highlight) ], md=2), hide=self.hide_highlight), make_hideable(dbc.Col([self.selector.layout()], md=2), hide=self.hide_selector) ]), dbc.Row([ dbc.Col([ html.Div(id="decisionpath-table-" + self.name), ]), ]), ]), ])
def get_currency_converter(current_price, symbol): all_curr = current_price.keys() return [ dbc.Row([ dbc.Col( dbc.InputGroup([ dbc.Input(id='eth-side-1', type="number", value=1, step=1), dbc.InputGroupAddon(symbol.upper(), addon_type="append") ]), ), dbc.Col( dbc.Select( id='curr-select-1', options=[{ 'label': curr.upper(), 'value': curr } for curr in all_curr], value='usd', )), dbc.Col(dbc.Input(id='result-side-1', disabled=True)), ], align='center', justify='center'), html.Br(), dbc.Row([ dbc.Col( dbc.Input(id='result-side-2', type="number", step=1, value=1)), dbc.Col( dbc.Select( id='curr-select-2', options=[{ 'label': curr.upper(), 'value': curr } for curr in all_curr], value='usd', )), dbc.Col( dbc.InputGroup([ dbc.Input(id='eth-side-2', disabled=True), dbc.InputGroupAddon(symbol.upper(), addon_type="append") ]), ), ], align='center', justify='center') ]
def make_select_component(title, opts, id): return dbc.FormGroup( [ dbc.Label(title), dbc.Select( id=id, options=opts, ), ] )
def EmailIssueSelect(): return dbc.InputGroup([ dbc.Select( id='issue-select', options=[{"label": "Bug report", "value": EmailIssueReference.BUG.value}, {'label': 'I Forgot my password', 'value': EmailIssueReference.FORGOT_PSSWRD.value}, {"label": "General inquiry", "value": EmailIssueReference.OTHER.value}] ), dbc.InputGroupAddon("Subject", addon_type="prepend"), ])
def _manage_parameters_group(self): return dbc.FormGroup([ dbc.Label('Manage parameters'), dbc.Select(id='params-select', options=[]), dbc.Button('Remove parameter', id='remove-param-button', color='danger', className='mr-1', style=element_style()) ])
def generate_document_topic_dropdown( self ): """ Generate a Dash dropdown component to select a topic from the model. """ # create the options topic_options = self.__build_topic_options() # create the Dash form component return dbc.Select( id='topic-document-dropdown', options=topic_options, value=topic_options[0]["value"] )
def target(): return dbc.Select( id="target_dropdown", options=population_options, value=POPULATION['Recidivist'], style={ 'color': '#242426', 'background-color': '#bfbfbf' }, )
def geography(): return dbc.Select( id="geographic_dropdown", options=geographic_options, value=GEOGRAPHIC['Department'], style={ 'color': '#242426', 'background-color': '#bfbfbf' }, )
def _build_select_parameter(): return dbc.Col( [ dbc.Label("Parameter"), dbc.Select( id=PARAMETER_SELECT, options=[], ), ] )
def create_select(field): """ Create Select Field :param field: :return: """ return dbc.Select(id="input_{}".format(field['Label']), options=[{ "label": option, "value": key } for key, option in enumerate(field['Options'])])
def generate_topic_dropdown( self ): topic_options = [] num_fmt = "Topic %02d" if self.metadata["k"] < 100 else "Topic %03d" for topic_index in range( 1, self.metadata["k"] + 1 ): label = num_fmt % topic_index topic_options.append( { "label": label, "value": topic_index } ) return dbc.Select( id='topic-sil-dropdown', options=topic_options, value=topic_options[0]["value"] )
def function_type(index): type_label = dbc.InputGroupAddon("Type", addon_type="prepend") val = "Exponential" if data is None else data["type"] type_select = dbc.Select( options=[ {"label": "Gaussian", "value": "Gaussian"}, {"label": "Lorentzian", "value": "Exponential"}, ], value=val, id={"function": "apodization", "args": "type", "index": index}, ) return dbc.InputGroup([type_label, type_select], className="input-form")
def generate_heatmap_topic_dropdown(self): """ Generate a Dash dropdown component to select a topic from the model. """ # create the options topic_options = [] num_fmt = "Topic %02d" if self.metadata["k"] < 100 else "Topic %03d" for topic_index in range(1, self.metadata["k"] + 1): label = num_fmt % topic_index topic_options.append({"label": label, "value": topic_index}) # create the Dash form component return dbc.Select(id='termlevel-dropdown', options=topic_options, value=topic_options[0]["value"])
def AdditionalTrackFormatSelector(): format_list = sorted([{"label": '{} ({})'.format(track.name, track.value), "value": track.name} for track in AdditionalDatasetReference], key=lambda k: k['value']) return dbc.InputGroup( [ dbc.Select( id='additional-track-selector', options=format_list ), dbc.InputGroupAddon("Track", addon_type="append"), ] )
def _build_select_attributes(): return [ dbc.Col( [ dbc.Label("X-Axis Attribute"), dbc.Select( id=X_ATTRIBUTE_SELECT, options=[], ), ] ), dbc.Col( [ dbc.Label("Y-Axis Attribute"), dbc.Select( id=Y_ATTRIBUTE_SELECT, options=[], ), ] ), ]
def make_new_prem(text, type_0, type_1, type_2): return dbc.FormGroup([ dbc.Label(text), dbc.Select( options=[{ 'label': p, 'value': p } for p in PROPS_WITH_NEG], style={'max-width': '20px'}, ), ], row=True)
def wrap_select_div(form_text: str, id: str, options: List[Dict], value: Union[None, str] = None) -> html.Div: return html.Div( dbc.FormGroup([ dbc.FormText(form_text), dbc.Select( id=id, options=options, value=value ), ]) )
def _weapon_enable_input(self): return dbc.InputGroup([ dbc.Select( options=[ {'label': 'Enabled', 'value': 'enabled'}, {'label': 'Disabled', 'value': 'disabled'} ], value='enabled' if self.weapon_index == 0 else 'disabled', disabled=self.weapon_index == 0, persistence=True, persistence_type='session', id=f'weaponenabled_{self.tab_index}_{self.weapon_index}', ), ], size="sm")