def getGraph(children, dim): if (children == None): raise PreventUpdate searchDate = children.strip('Sun_') searchDate = searchDate.strip('.fits') if (dim): slide = [ Span([ 'Order Range\n' ], id='order-tool', className=''), Span([ 'Resolution\n' ], id='res-tool', className='d-none') ] regex = two.find_one({'filename': {'$regex': '.*' + searchDate + '.*'}}) if regex: res = read_csv(regex).to_json() return res, 'row justify-content-end', 'col', 'col d-none', slide res = read_csv(two.find_one({})).to_json() return res, 'row justify-content-end', 'col', 'col d-none', slide slide = [ Span([ 'Order Range\n' ], id='order-tool', className='d-none'), Span([ 'Resolution\n' ], id='res-tool', className='') ] regex = one.find_one({'filename': {'$regex': '.*' + searchDate + '.*'}}) if regex: res = read_csv(regex).to_json() return res, 'row justify-content-end', 'col d-none', 'col', slide res = read_csv(one.find_one({})).to_json() return res, 'row justify-content-end', 'col d-none', 'col', slide
def Alert(message): return Div(id="alert-div", className="alert alert-warning alert-dismissible", children=[ Button(className="close", type='button', children=[Span("x")], **{ "data-dismiss": "alert", "aria-label": "Close" }), Strong("Warning!"), f" {message}", ])
df = read_observations(['LB', 'MUZ'], 2018) df = df[df.index > '2018-12-01'] dflb = df[df.site == 'LB'] config = {'edits': {'shapePosition': True}} graphdcc = dcc.Graph(id='tested_graph', figure=wind_figure(dflb, times=[('2018-12-12', '2018-12-13')]), style={ "width": "98%", 'height': '98%' }, config=config) div0 = TileDiv([Span("Page de test des tracés", className='app-title')], className="header") div1 = TileDiv([graphdcc], nrows=8, className='chart_div') div2 = TileDiv( [H1("Relayout data"), P(id='relayout-data')], nrows=4, className='chart_div') div3 = TileDiv([P('some text')], className='chart_div') apptest.layout = Div(generate_layout(div0, div1, div2, div3)) @apptest.callback(Output('relayout-data', 'children'), [Input('tested_graph', 'relayoutData')]) def display_selected_data(relayoutData): return json.dumps(relayoutData, indent=2)
def monthly_html_table() -> Div: """ Build pretty monthly transaction table with names as indices and months as columns """ df = transactions_monthly() df.index = [s.strftime('%b %y') for s in df.index] expenses = [n for n in NAMES if n in df.columns and df[n].sum() <= 0] income = [n for n in NAMES if n in df.columns and df[n].sum() > 0] df = df[expenses + income].T curr = ' {:,.2f}'.format perc = '{:,.2%}'.format def circle(color): css = { 'width': '14px', 'height': '14px', 'background': color, 'display': 'inline-block', 'margin': '0 8px 0 0', 'padding': 0 } return Div(style=css) header_row = Thead([Th('Name', scope='col')] + [Th(col, scope='col') for col in df.columns], className='thead-light') # name rows name_rows = [] for cat, row in df.iterrows(): cells = [ Th([circle(color(cat)), cat], scope='row', style={'background': '#fafafa'}) ] for cell in row: style = { 'color': color('INC') if cell >= 0 else color('EXP'), 'text-align': 'right' } cells.append(Td(curr(cell or '') if cell != 0 else '', style=style)) name_rows.append(Tr(cells)) # growth row balances = list(df.sum().cumsum() + BALANCE) saving_rel = np.divide(balances, [BALANCE] + balances[:-1]) - 1 saving_abs = np.array(balances) - np.array([BALANCE] + balances[:-1]) growth_row = [ Th('GROWTH', style={ 'background': '#f5f5f5', 'border-top': 'solid 2px #CCC' }) ] for sr, sa in zip(saving_rel, saving_abs): sa = Span(curr(sa), style={ 'color': color('INC') if sr >= 0 else color('EXP'), 'font-weight': 'bold' }) sr = Span( f'{perc(sr)}', style={ 'color': color('INC', alpha=0.8) if sr >= 0 else color('EXP', alpha=0.8) }) sep = Span(' | ', style={'color': '#CCC'}) growth_row.append( Td([sr, sep, sa], style={ 'border-top': 'solid 2px #CCC', 'text-align': 'right' })) growth_row = Tr(growth_row) # total row total_row = [Th('TOTAL', style={'background': '#f5f5f5'})] for exp, inc in zip(df.loc[expenses].sum(), df.loc[income].sum()): sexp = Span(curr(exp), style={ 'color': color('EXP'), 'font-weight': 'bold' }) sinc = Span(curr(inc), style={ 'color': color('INC'), 'font-weight': 'bold' }) sep = Span(' | ', style={'color': '#CCC'}) total_row.append(Td([sexp, sep, sinc], style={'text-align': 'right'})) total_row = Tr(total_row) # balance row balance_row = [Th('BALANCE', style={'background': '#f5f5f5'})] for diff in df.sum().cumsum() + BALANCE: balance_row.append( Td(curr(diff), style={ 'font-weight': 'bold', 'text-align': 'right' })) balance_row = Tr(balance_row) all_rows = [header_row] + name_rows + [growth_row] + [total_row ] + [balance_row] return Div(Table(all_rows, className='table table-bordered table-sm'), className='table-responsive-sm')
def wordloud_controls(id_prefix, default_mask=None, min_font_size=4): c = Div([ Div([ Div([ Div([ Button('Build', className="btn btn-success", n_clicks=1, id='{0}-generate-wordcloud'.format(id_prefix), style={'width': '100%'}) ], className='col mb-2') ], className='row'), Div([ Div([ Div([Span('Stop Words', className='input-group-text')], className='input-group-prepend'), dcc.Input(id='{0}-stopwords'.format(id_prefix), value='show,episode,season,series,episodes,time,first,character,characters', placeholder='Stop Words (,)', className='form-control') ], className='col input-group mb-2') ], className='row'), Div([ Div([ Div([ Div([Span('Width', className='input-group-text')], className='input-group-prepend'), dcc.Input(id='{0}-width'.format(id_prefix), value=1000, inputMode='numeric', type='number', min=200, max=2000, className='form-control'), ], className='input-group mb-2 pr-0 pl-0') ], className='col-12 col-md-6'), Div([ Div([ Div([Span('Height', className='input-group-text')], className='input-group-prepend'), dcc.Input(id='{0}-height'.format(id_prefix), value=500, inputMode='numeric', type='number', min=200, max=2000, className='form-control'), ], className='input-group mb-2 pr-0 pl-0') ], className='col-12 col-md-6'), ], className='row'), Div([ Div([ Div([ Div([Span('Colorscale', className='input-group-text')], className='input-group-prepend'), dbc.Select(options=[{'label': i, 'value': i} for i in plt.colormaps()], value='viridis', id='{0}-colormap'.format(id_prefix), className='form-control') ], className='input-group mb-2') ], className='col-lg-6 col-md-6'), Div([ Div([ Div([Span('Background', className='input-group-text')], className='input-group-prepend'), dbc.Input(id='{0}-background-color'.format(id_prefix), value='#ffffff', type='color', className='form-control', style={'padding': 0, 'height': 38}) ], className='input-group mb-2'), ], className='col-lg-6 col-md-6'), ], className='row') ], className='col-lg-6'), Div([ Div([ Div([ Div([ Div([Span('Max font', className='input-group-text')], className='input-group-prepend'), dcc.Input(id='{0}-max-font'.format(id_prefix), value=0, inputMode='numeric', type='number', min=0, max=100, className='form-control'), ], className='input-group mb-2') ], className='col-6'), Div([ Div([ Div([Span('Min font', className='input-group-text')], className='input-group-prepend'), dcc.Input(id='{0}-min-font'.format(id_prefix), value=min_font_size, inputMode='numeric', type='number', min=1, max=100, className='form-control'), ], className='input-group mb-2') ], className='col-6') ], className='row'), Div([ Div([ Div([ Div([Span('Frq/Rnk', className='input-group-text')], className='input-group-prepend'), dcc.Input(id='{0}-scaling'.format(id_prefix), value=0.5, min=0, max=1, step=0.01, inputMode='numeric', type='number', className='form-control pb-0'), ], className='input-group mb-2') ], className='col-lg-6 col-md-6'), Div([ Div([ Div([Span('Max Words', className='input-group-text')], className='input-group-prepend'), dcc.Input(id='{0}-nwords'.format(id_prefix), value=200, inputMode='numeric', type='number', min=10, max=500, step=10, className='form-control'), ], className='input-group mb-2') ], className='col-lg-6 col-md-6') ], className='row'), Div([ Div([ Div([ Div([Span('Mask URL', className='input-group-text')], className='input-group-prepend'), dcc.Input(id='{0}-image-mask-url'.format(id_prefix), value=default_mask, inputMode='url', type='search', className='form-control'), ], className='input-group mb-2') ], className='col-lg-12 col-md-12'), ], className='row'), Div([ Div([ Div([ Div([Span('Scale', className='input-group-text')], className='input-group-prepend'), dcc.Input(id='{0}-scale'.format(id_prefix), value=1, inputMode='numeric', type='number', min=1, max=10, className='form-control'), ], className='input-group mb-2 pr-0 pl-0') ], className='col-12 col-md-6'), Div([ A('Save', download='wordcloud.png', href="", target="_blank", className="btn btn-primary", id='{0}-save-wordcloud'.format(id_prefix), style={'width': '100%'}) ], className='col-md-6 mb-2') ], className='row') ], className='col-lg-6'), Div([ Details([ Summary('Help'), dcc.Markdown(instructions) ], className='col-sm-12') ]) ], className='row') return c
H2('', className='card-title'), Div([Img(src='', className='card-img-top', width='100%')], style={'height': 500}), ], className='card-body', id='custom-wiki-wordcloud'), style={ 'paddingTop': 200, 'paddingBottom': 200 }, type='dot'), Div([ Div([ Div([ Div([ Span('Article', className='input-group-text') ], className='input-group-prepend'), dcc.Input(id='custom-wiki-url', value='The Simpsons', placeholder='Article Name', className='form-control'), Div([ Button('Random!', className="btn btn-outline-secondary", id='cusotm-wiki-random') ], className='input-group-append') ], className='col-sm-12 input-group mb-2') ],
def scenario_input_card(scen_name): """ Function to create the scenario input boxes """ return Div( children=[ Div( P([ "Number of big companies: ", Span( "\u003f\u20dd", id=scen_name + "-tooltip-num-big-firms", className="question-mark", ), ]), style={"margin-left": 2}, ), dbc.Tooltip( HOVERTEXTS["Number of big companies"], target=scen_name + "-tooltip-num-big-firms", style=TOOLTIP_STYLE, placement="right", arrowClassName="arrow", ), RadioItems( id=scen_name + "-num-big-firms", options=[{ "label": x, "value": x } for x in [1, 2, 3, 4, "None"]], labelStyle={ "display": "inline-block", "margin-right": "15px" }, inputStyle={ "margin-right": "6px", "verticalAlign": "middle" }, value=1, style={"margin-bottom": "4%"}, ), Div( P([ "Privacy concerns from customers: ", Span( "\u003f\u20dd", id=scen_name + "-tooltip-privacy-concern", className="question-mark", ), ]), style={"margin-left": 2}, ), dbc.Tooltip( HOVERTEXTS["Privacy concern"], target=scen_name + "-tooltip-privacy-concern", style=TOOLTIP_STYLE, placement="right", ), RadioItems( id=scen_name + "-privacy-concern", options=[{ "label": x, "value": x.lower() } for x in ["Low", "Medium", "High"]], labelStyle={ "display": "inline-block", "margin-right": "15px" }, inputStyle={ "margin-right": "10px", "verticalAlign": "middle" }, value="medium", style={"margin-bottom": "4%"}, ), Div( P([ "Consumer preference for multiple products from the same company: ", Span( "\u003f\u20dd", id=scen_name + "-tooltip-loyalty", className="question-mark", ), ]), style={"margin-left": 2}, ), dbc.Tooltip( HOVERTEXTS[ "Consumer preference for multiple products from the same company"], target=scen_name + "-tooltip-loyalty", style=TOOLTIP_STYLE, placement="right", ), RadioItems( id=scen_name + "-loyalty", options=[{ "label": x, "value": x.lower() } for x in ["Low", "Medium", "High"]], labelStyle={ "display": "inline-block", "margin-right": "15px" }, inputStyle={ "margin-right": "10px", "verticalAlign": "middle" }, value="medium", style={"margin-bottom": "4%"}, ), Div( P([ "Openness: ", Span( "\u003f\u20dd", id=scen_name + "-tooltip-openness", className="question-mark", ), ]), style={"margin-left": 2}, ), dbc.Tooltip( HOVERTEXTS["Openness"], target=scen_name + "-tooltip-openness", style=TOOLTIP_STYLE, placement="right", ), RadioItems( id=scen_name + "-openness", options=[{ "label": x, "value": x.lower() } for x in ["Low", "Medium", "High"]], labelStyle={ "display": "inline-block", "margin-right": "15px" }, inputStyle={ "margin-right": "10px", "verticalAlign": "middle" }, value="medium", style={"margin-bottom": "4%"}, ), P( [ "Privacy shock ", Span( "\u003f\u20dd", id=scen_name + "-tooltip-privacy", className="question-mark", ), ], style={ "margin-bottom": "0%", "margin-left": 2 }, ), P( "(can be applied to several firms)", style={ "font-size": "12px", "margin-bottom": "0%" }, ), dbc.Tooltip( HOVERTEXTS["Privacy shock"], target=scen_name + "-tooltip-privacy", style=TOOLTIP_STYLE, placement="right", ), Checklist( id=scen_name + "-privacy-onoff", options=[{ "label": "Include a privacy shock", "value": True }], values=[], inputStyle={"margin-right": "5px"}, style={ "margin-bottom": "2%", "margin-top": "0%" }, ), RadioItems( id=scen_name + "-shock-num", options=[{ "label": x, "value": x } for x in [1, 2, 3, 4]], labelStyle={ "display": "inline-block", "margin-right": "15px", "padding-bottom": ITEM_BOTTOM, }, inputStyle={"margin-right": "10px"}, value=1, style={"margin-bottom": "4%"}, ), ], className="scenario-input", style={ "background-color": "rgb(234, 234, 234)", "font-size": "16px" }, )
"background-color": "rgb(234, 234, 234)", "font-size": "16px" }, ) # Layout app.layout = Div( [ Div([Store(x + "-store-" + str(i)) for x in TAB_DICT.keys() for i in [1, 2]]), # header Div( Div( children=[ Span( "Using an ‘agent based model’ for data policy decision-making" ), Div( A( Img( src="/assets/basic-W-48px.png", height="80%", style={"align": "center"}, ), href="https://theodi.org", target="_blank", ), className="brandimage", ), ], className="insideheader",
def update(): if request.endpoint == url_base: app.index_string = render_template( 'data_page.html' ) rv = rv_plot.public curr_user = g.user['atype'] if curr_user == 'admin' or curr_user == 'researcher': rv = rv_plot.data app.layout = Div([ Tooltip( "Set the Y axis to a linear or logarithmic scale.", target="log-switch", ), Tooltip( "Enables data to be separated by order on the spectrograph", target="dim-switch", ), Tooltip( "The name of the file being displayed", target="click-data", placement="bottom" ), Tooltip( "Selects which orders of the spectrum to render", target="order-tool", ), Tooltip( "Reduces the amount of points rendered to the screen", target="res-tool", ), Tooltip( "Each graph has a tool bar in the upper-right hand corner that appears when you mouse over a graph." "Use the buttons in the tool bar to zoom in, zoom out, reset the axis, save a screen shot, " "and more. Click on a point in the Radial Velocity graph to display the Spectrum graph below." "Hover over the slider and toggle bottoms below the lower graph to further interact with the" "spectrum data.", target="graph-tool" ), Loading([ Div([ Button([ I( className="fas fa-info-circle", ), Span( ' Info', ) ], id='graph-tool', className='btn btn-warning btn-sm', ), ]), Div( id='rv-download-container' ), Button([ I( className="fas fa-download", ), Span( " Download Radial Velocities", ) ], id='rv-download', className='btn btn-primary btn-sm float-right', ), Download( id='rv-download-data' ), DatePickerRange( id='date-range', className='pt-1 d-flex justify-content-end w-100', ), Graph( id='rv-plot', className="", config={ 'modeBarButtonsToRemove': ['pan2d', 'lasso2d', 'autoscale'] } ), ], type="default", className='d-flex justify-content-end w-100'), Div( id='rv-data', children=rv[rv_label].to_json(), className='d-none' ), Div([ Pre(id='click-data', className=' d-inline'), ]), Br(), Br(), Div([ Loading([ Div([ Div([ Button([ I( className="fas fa-download", ), Span( " Download 1D", ) ], id='1d-spec-download', className='btn btn-primary btn-sm', ), Download( id='1d-spec-download-data' ), ], className='pr-2'), Div([ Button([ I( className="fas fa-download", ), Span( " Download 2D", )], id='2d-spec-download', className='btn btn-primary btn-sm', ), Download( id='2d-spec-download-data' ), ], className=""), ], className="row justify-content-end d-none", id="spec-download-container"), Div( id='spec-data', children=[], className='d-none' ), Graph( id='spec-plot', className="pt-0", config={ 'modeBarButtonsToRemove': ['pan2d', 'lasso2d', 'autoscale'] } ), ], type="default", ), Div([ Span([ 'Order Range\n' ], id='order-tool', className='d-none'), Span([ 'Resolution\n' ], id='res-tool', className='d-none') ], id='slide-label', className='w-100 text-center'), Div([ Slider( min=1, max=200, value=100, marks={ 1: {'label': '1:1', 'style': {'color': '#77b0b1'}}, 20: {'label': '20:1'}, 50: {'label': '50:1'}, 100: {'label': '100:1'}, 200: {'label': '200:1', 'style': {'color': '#f50'}} }, id='resolution', className='col d-none', ), RangeSlider( id='spec-range', className='col d-none', min=0, max=85, step=1, value=[40, 45], marks={ 0: {'label': '0'}, 40: {'label': '40'}, 45: {'label': '45'}, 85: {'label': '85'} } ), ], className='row'), ], id='spec-container'), Br(), Div([ Div([ daq.ToggleSwitch( label='lin/log', id='log-switch', className='d-inline-block', labelPosition='bottom' ), ], className='col text-center'), Div([ daq.ToggleSwitch( label='1D / 2D', id='dim-switch', className='d-inline-block', labelPosition='bottom' ) ], className='col text-center'), ], className="row") ])
'title': { 'text': graph_label['rv_y'], 'font': { 'size': 18, 'color': '#7f7f7f' } }, } rv_plot.result = dumps({'data': [fig], 'layout':{'xaxis':x_axis, 'yaxis':y_axis}, 'config': {'responsive': True}}, cls=plotly.utils.PlotlyJSONEncoder) rv_plot.public = rv return rv tool = Span( "floccinaucinihilipilification", id="tooltip-target", style={"textDecoration": "underline", "cursor": "pointer"}, ) def init_graphing(server): #fs = gridfs.GridFS(mongo.db) with server.app_context(): one = get_fs('one') two = get_fs('two') rv = rv_plot(server) app = Dash( '__main__', server=server,
sticky="top", ) body = boots.Container( [ boots.Row( [ boots.Col( [ H1( 'Search Stocks', className='', id='' ), Span( 'Examples: COKE, TSLA, MSFT, CYH.' ), core.Input( id='ticker_input', value='MSFT', className='input' ) ], className='col-4 mb-4' ), boots.Col( [ H1( 'Stock Data', className='', id='stock-name'
import matplotlib matplotlib.use('Agg') from dash_html_components import Div, Img, Button, H2, H1, P, Hr, A, Span, Label, Hr, Footer, Ul, Li, Meta import dash_core_components as dcc from dash.dependencies import Output, Input, State from apps import wikipediaWordCloud, lyricsWordCloud, textFieldWordCloud, textUploadWordCloud, wordCloud from app import app from templates.wordcloud import footer server = app.server navbar = Div([ Div(['Word Cloud World', ], className='navbar-brand'), Button(Span(className='navbar-toggler-icon'), className='navbar-toggler', type="button", **{'data-toggle': "collapse", 'data-target': "#navbarNav", 'aria-controls': "navbarNav", 'aria-expanded': "false", 'aria-label': "Toggle navigation"}), Div([ Ul([ Li(dcc.Link('Home', href="/", className='nav-link'), className='nav-item', style={'cursor': 'pointer'}), Li(dcc.Link('Wiki Cloud', href="/wordcloud/wikipedia", className='nav-link'), className='nav-item', style={'cursor': 'pointer'}), Li(dcc.Link('Lyrics Cloud', href="/wordcloud/lyrics", className='nav-link'), className='nav-item', style={'cursor': 'pointer'}), Li(dcc.Link('Upload Cloud', href="/wordcloud/textupload", className='nav-link'), className='nav-item', style={'cursor': 'pointer'}), Li(dcc.Link('Copy & Paste Cloud', href="/wordcloud/textfield", className='nav-link'), className='nav-item', style={'cursor': 'pointer'}) ], className='navbar-nav') ], className='collapse navbar-collapse', id="navbarNav") ], className='navbar navbar-dark bg-dark navbar-expand-lg') app.layout = Div([ Meta(name="viewport", content="width=device-width, initial-scale=1, shrink-to-fit=no"),
dcc.Loading(Div([ H2('', className='card-title'), Div([Img(src='', className='card-img-top', width='100%')], style={'height': 500}) ], className='card-body', id='lyrics-wordcloud'), style={ 'paddingTop': 200, 'paddingBottom': 200 }, type='dot'), Div([ Div([ Div([ Div([Span('Artist', className='input-group-text')], className='input-group-prepend'), dcc.Input(id='lyrics-artist', value='Rick Astley', placeholder='Artist', className='form-control'), ], className='col-sm-6 input-group mb-2'), Div([ Div([Span('Song', className='input-group-text')], className='input-group-prepend'), dcc.Input(id='lyrics-song', value='Never Gonna Give You Up', placeholder='Song', className='form-control'), ],