def __init__(self, pi_data): self.app = dash.Dash(__name__) self.app.layout = dhtml.Div([ dcc.Graph(id='live-pi-graph', animate=True), dcc.Interval(id='update-graph', interval=900), dhtml.Output(id='pi-output'), dhtml.Div([dhtml.Output(id='digit-count')])]) self.ix = 0 self.pi_string = '3.' self.digit_counter = 'Digits printed: {}'.format(len(self.pi_string)-2) self.pi_data = pi_data[2:] #Skip '3.' self.data_length = len(self.pi_data) self.y_axis = deque(maxlen=150) self.x_axis = deque(maxlen=150) self.count = 0 @self.app.callback(Output('live-pi-graph', 'figure'), events=[Event('update-graph', 'interval')]) def updateGraph(): if self.ix < self.data_length: self.x_axis.append(self.ix) self.y_axis.append(self.pi_data[self.ix]) self.ix +=1 data = pgo.Scatter(x=list(self.x_axis), y=list(self.y_axis), name="Digits of Pi", mode = 'lines+markers', marker=dict(size=10, color='rgba(255, 0, 0, .9)', line=dict(width=2))) return {'data': [data], 'layout': pgo.Layout(title='Pi Day 2018 by @swoldemi', xaxis=dict(range=[min(self.x_axis), max(self.x_axis)]), yaxis=dict(range=[0, 12]), autosize=True)} else: sys.exit(0) @self.app.callback(Output(component_id='pi-output', component_property='children'), events=[Event('update-graph', 'interval')]) def printPi(): if self.ix-1 < self.data_length: self.pi_string = self.pi_string + self.pi_data[self.ix-1] self.count +=1 if self.count > 2: self.pi_string = self.pi_string + '\n' self.count = 0 return self.pi_string @self.app.callback(Output(component_id='digit-count', component_property='children'), events=[Event('update-graph', 'interval')]) def displayDigitCount(): self.digit_counter = 'Digits printed: {}'.format(len(self.pi_string)-2) return self.digit_counter
def test_stda002_nested_data(dash_duo): app = dash.Dash(__name__) nested = {"nested": {"nest": "much"}} nested_list = dict(my_list=[1, 2, 3]) app.layout = html.Div([ dcc.Store(id="store", storage_type="local"), html.Button("set object as key", id="obj-btn"), html.Button("set list as key", id="list-btn"), html.Output(id="output"), ]) @app.callback( Output("store", "data"), [ Input("obj-btn", "n_clicks_timestamp"), Input("list-btn", "n_clicks_timestamp"), ], ) def on_obj_click(obj_ts, list_ts): if obj_ts is None and list_ts is None: raise PreventUpdate # python 3 got the default props bug. plotly/dash#396 if (obj_ts and not list_ts) or obj_ts > list_ts: return nested else: return nested_list @app.callback( Output("output", "children"), [Input("store", "modified_timestamp")], [State("store", "data")], ) def on_ts(ts, data): if ts is None: raise PreventUpdate return json.dumps(data) dash_duo.start_server(app) obj_btn = dash_duo.wait_for_element("#obj-btn") list_btn = dash_duo.find_element("#list-btn") obj_btn.click() dash_duo.wait_for_text_to_equal("#output", json.dumps(nested)) # it would of crashed the app before adding the recursive check. list_btn.click() dash_duo.wait_for_text_to_equal("#output", json.dumps(nested_list))
def test_store_nested_data(self): app = dash.Dash(__name__) nested = {'nested': {'nest': 'much'}} nested_list = dict(my_list=[1, 2, 3]) app.layout = html.Div([ dcc.Store(id='store', storage_type='local'), html.Button('set object as key', id='obj-btn'), html.Button('set list as key', id='list-btn'), html.Output(id='output') ]) @app.callback(Output('store', 'data'), [ Input('obj-btn', 'n_clicks_timestamp'), Input('list-btn', 'n_clicks_timestamp') ]) def on_obj_click(obj_ts, list_ts): if obj_ts is None and list_ts is None: raise PreventUpdate # python 3 got the default props bug. plotly/dash#396 if (obj_ts and not list_ts) or obj_ts > list_ts: return nested else: return nested_list @app.callback(Output('output', 'children'), [Input('store', 'modified_timestamp')], [State('store', 'data')]) def on_ts(ts, data): if ts is None: raise PreventUpdate return json.dumps(data) self.startServer(app) obj_btn = self.wait_for_element_by_css_selector('#obj-btn') list_btn = self.wait_for_element_by_css_selector('#list-btn') obj_btn.click() time.sleep(3) self.wait_for_text_to_equal('#output', json.dumps(nested)) # it would of crashed the app before adding the recursive check. list_btn.click() time.sleep(3) self.wait_for_text_to_equal('#output', json.dumps(nested_list))
[ html.H3('Visual Behavior Data QC Viewer'), # checklist for components to show html.Div([components.show_overview_checklist], style={'display': 'none'}), components.plot_inventory_graph_div, # container level dropdown components.container_overview_dropdown, # frame with container level plots components.container_overview_iframe, components.plot_inventory_iframe, html.H4('Find container from experiment ID:'), html.Label('Enter experiment ID:'), dcc.Input(id='experiment_id_entry', placeholder=''), html.Label('| Corresponding Container ID: '), html.Output(id='container_id_output', children=''), html.H4('Choose how to organize data:'), components.display_level_selection, html.H4('Choose preferred path style:'), components.path_style, html.H4('Data Table:'), html.I('Adjust number of rows to display in the data table:'), components.table_row_selection, components.reload_data_button, components.update_data_button, # data table components.data_table, # dropdown for plot selection components.previous_button, components.next_button, html.Div(id='stored_feedback', style={'display': 'none'}),
stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css'] # App: app = dash.Dash(__name__, external_stylesheets=stylesheets) # Layout: app.layout = html.Div([ html.Div([ 'X = ', dcc.Input(id='input', type='number', value=10) ], style={'width': '49%', 'display': 'inline-block'} ), html.Div([ html.Td(['x', html.Sup('2'), ' = '], style={'display': 'inline-block'}), html.Output(id='square') ]), html.Div([ html.Td(['x', html.Sup('3'), ' = '], style={'display': 'inline-block'}), html.Output(id='cubic') ]) ]) # Callback: @app.callback([Output('square', 'children'), Output('cubic', 'children')], [Input('input', 'value')] ) def update(x): if x is None:
server.secret_key = os.environ.get('secret_key', 'secret') engine = sqlalchemy.create_engine( '{dialect}://{username}:{password}@{host}:{port}/{schema}'.format( dialect='postgres', username='******', password='******', host='readonly-test-postgres.cwwxgcilxwxw.us-west-2.rds.amazonaws.com', port=5432, schema='plotly_datasets')) engine.pool._use_threadlocal = True app.layout = html.Div([ html.Button('Add a CPU bound request', id='cpu-click', n_clicks=0), html.Output(id='cpu-container'), html.Button('Add a IO bound request', id='io-click', n_clicks=0), html.Output(id='io-container'), html.Button('gevent sleep', id='gevent-sleep-click', n_clicks=0), html.Output(id='gevent-sleep-container'), ]) @app.callback(dash.dependencies.Output('cpu-container', 'children'), [dash.dependencies.Input('cpu-click', 'n_clicks')]) def process(n_clicks): print("Processing cpu request #{}".format(n_clicks)) time.sleep(10) return 'Done (request #{})'.format(n_clicks)
def no_images_msg(): return html.div([html.Output(id='no_images', value="No images found")])
# Submit button: html.Button('Submit', id='submit-button', n_clicks = 0), # Line break html.Br(), # Div to hold the initial instructions and the updated info once submit is pressed html.Div(id='output-instruction', children='Enter a currency code and press \'submit\''), html.Div([ # Candlestick graph goes here: dcc.Graph(id='candlestick-graph') ]), # Another line break html.Br(), # Section title html.H1("Section 2: Make a Trade"), # Div to confirm what trade was made html.Output(id='output-trade-info', children=''), # Radio items to select buy or sell dcc.RadioItems( id='radio', options=[ {'label': 'Buy', 'value': 'buy'}, {'label': 'Sell', 'value': 'sell'} ], value='buy', labelStyle={'display': 'inline-block'} ), # Text input for the currency pair to be traded html.Div(dcc.Input(id='trade-currency-pair', placeholder="EURUSD", type='text')), # Numeric input for the trade amount html.Div(dcc.Input(id='trade-amount', placeholder=1000, type='number')), # Submit button for the trade
<dl> <p> <input type="file" name="file" multiple="true" autocomplete="off" required> </p> </dl> <p> <input type="submit" value="Submit"> </p> </form> </div> '''), html.Div([ html.Button( children='Convert', id='btn_convert_logs', formAction='/generate'), html.Br(), html.Output(id='out_convert_logs') ], style={'text-align': 'center'}) ]) external_scripts = [{ 'src': 'https://use.fontawesome.com/releases/v5.0.13/js/solid.js', 'integrity': 'sha384-tzzSw1/Vo+0N5UhStP3bvwWPq+uvzCMfrN1fEFe+xBmv1C/AtVX5K0uZtmcHitFZ', 'crossorigin': 'anonymous' }, { 'src': 'https://use.fontawesome.com/releases/v5.0.13/js/fontawesome.js', 'integrity': 'sha384-6OIrr52G08NpOFSZdxxz1xdNSndlD4vdcf/q2myIUVO0VsqaGHJsB0RaBE01VTOY', 'crossorigin': 'anonymous' }, {
id='top_genres', style={'color': 'white'}, n_clicks=0), html.Button('Top artists', id='top_artists', style={'color': 'white'}, n_clicks=0), html.Button('Top eras', id='top_eras', style={'color': 'white'}, n_clicks=0), html.Button('Analysis', id='analysis', style={'color': 'white'}, n_clicks=0), html.Output(id='output', children=''), dash_table.DataTable(id='table', fixed_rows={ 'headers': True, 'data': 0 }, style_header={'backgroundColor': '#1DB954'}), # dcc.Graph( # id='dance_ability', # figure={ # 'data': [ # {'x': top_tracks_features()['Title'], # 'y': top_tracks_features()['Danceability'], 'type': 'bar', 'name': 'HALO'}, # # ], # 'layout': {
children=[ html.Label('Select an Index'), dcc.Dropdown( id='index-dropdown-1', options=[{'label': i, 'value': i} for i in INDEX_SLUGS.keys()], value='Dow Jones Index', ), html.Label( 'Select an Index Constituent to Visualise: '), dcc.Dropdown( id='constituent-dropdown-1', value='MMM' ), html.H5('\n'), html.Output( id='graph-1',) ] ), # Column 2 Div html.Div( style={ 'width': '45%', 'display': 'inline-block', "margin": "0px 0px 0px 50px", }, children=[ html.Label('Select an Index'), dcc.Dropdown( id='index-dropdown-2', options=[{'label': i, 'value': i} for i in INDEX_SLUGS.keys()],