Ejemplo n.º 1
0
 def callback(__n_intervals__, *args, **kwargs):
     result_key = json.dumps({"args": list(args), "kwargs": kwargs})
     progress_key = result_key + "-progress"
     result = cache.get(result_key)
     progress = cache.get(progress_key)
     if result is not None:
         return dict(result=result, interval_disabled=True)
     elif progress is not None:
         return dict(
             result=html.Progress(
                 value=str(progress[0]),
                 max=str(progress[1]),
                 id=progress_id,
                 style=progress_style,
             ),
             interval_disabled=False,
         )
     else:
         target = make_update_cache(fn, cache, result_key, progress_key)
         p = Process(target=target, args=args, kwargs=kwargs)
         p.start()
         return dict(
             result=html.Progress(id=progress_id, style=progress_style),
             interval_disabled=False,
         )
Ejemplo n.º 2
0
def get_loader(df=data):
    """
    This function generates a loading bar that shows the current data you are working with and
     its proportion to all data.

    :param df: Initial data
    :return: Loading bar for data used
    :rtype: dcc.Loading
    """
    return dcc.Loading(className='loader',
                       id='loading',
                       type='default',
                       children=[
                           dcc.Markdown(
                               id='data_summary_filtered',
                               children=f'{len(df):,d} taxi trips selected'),
                           html.Progress(id='selected_progress',
                                         max=f'{initial_length}',
                                         value=f'{len(df)}'),
                       ])
Ejemplo n.º 3
0
import dash_core_components as dcc
from flask import Flask
from flask_socketio import SocketIO
from threading import Timer

eventlet.monkey_patch()
server = Flask(__name__, static_url_path='')
socket = SocketIO(server, async_mode='eventlet')
app = dash.Dash(__name__, server=server)

app.scripts.config.serve_locally = True
app.css.config.serve_locally = True

app.layout = html.Div([
    sockettest.sockettest(),
    html.Progress(id='progress', max=10, value=0),
    dcc.Slider(id='slider', value=0, min=0, max=10, step=1),
    html.Div(id='divspace'),
    html.Div(id='dummy'),
    html.Div(id='dummy1'),
    html.Div(id='dummy2')
])


@app.callback(Output('dummy', 'children'), [Input('progress', 'value')])
def func(value):
    print('progress', value)
    return None


@app.callback(Output('dummy1', 'children'), [Input('divspace', 'children')])
Ejemplo n.º 4
0
            'value': 'gao_dataset_noshap'
        },
        # {'label': 'waseem', 'value': 'waseem_dataset'},
        # {'label': 'mnist-mini', 'value': 'mnist'},
    ],
    clearable=False,
    searchable=False,
    value='')

submit_dataset = html.Button('Submit', id='start', autoFocus=True)

queries = dcc.Loading(html.Div(id='queries'))

url = dcc.Location(id='url')

progress_bar = html.Progress(id='progress', value=0, max=100)

###################
color = dcc.RadioItems(id='color',
                       options=[
                           {
                               'label': 'Color-code explanations',
                               'value': True
                           },
                           {
                               'label': 'No color-code for explanations',
                               'value': False
                           },
                       ],
                       value=False)
Ejemplo n.º 5
0
_layout = html.Div(
    className='row',
    id=PAGE_ID,
    children=[
        # Controls | Html table
        html.Div(className='four columns',
                 children=[
                     html.Div(dcc.Dropdown(id=ID('category'),
                                           value=[],
                                           multi=True,
                                           placeholder='Category ...',
                                           options=category_options()),
                              style={'display': 'block'}),
                     html.Div('loading ...', id=DISPLAY)
                 ]),
        html.Progress(max=100, value=60),

        # modal display
        html.Div(html.Div(html.Div(
            [
                html.Div([
                    html.
                    I(id=ID('modal-close'),
                      n_clicks=0,
                      className='fas fa-times w3-button w3-display-topright'),
                    html.H1('  ', id=ID('modal-header')),
                ],
                         className='w3-container w3-teal'),
                html.Div(
                    [
                        dcc.Interval(
import dash
import dash_html_components as html
import dash_core_components as dcc
import dash_bootstrap_components as dbc
from dash.dependencies import Input, Output
app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])

app.layout = html.Div([
    dcc.Interval(id="progress-interval", n_intervals=0, interval=110),
    html.Progress(id="html_progress",
                  max='100',
                  contentEditable="Yes",
                  children='Ohh Yess'),
    dbc.Spinner(color="primary")
])


@app.callback(
    [Output("html_progress", "value"),
     Output("html_progress", "style")],
    [Input("progress-interval", "n_intervals")],
)
def update_progress(n):
    # check progress of some background process, in this example we'll just
    # use n_intervals constrained to be in 0-100
    progress = min(n % 110, 100)
    #print(progress)
    # only add text after 5% progress to ensure text isn't squashed too much
    return str(progress), {
        'content': 'progress',
        'position': 'absolute',
Ejemplo n.º 7
0
    def __init__(self, long_callback_manager=None):
        """
        Parameters
        ----------
        long_callback_manager
            Optional callback manager for long callbacks.
            See https://dash.plotly.com/long-callbacks
        """
        super(BranchProInferenceApp, self).__init__()

        self.app = dash.Dash(__name__,
                             external_stylesheets=self.css,
                             long_callback_manager=long_callback_manager)
        self.app.title = 'BranchproInf'

        self.session_data = {
            'data_storage': None,
            'interval_storage': None,
            'posterior_storage': None
        }

        button_style = {
            'width': '100%',
            'height': '60px',
            'lineHeight': '60px',
            'borderWidth': '1px',
            'borderStyle': 'dashed',
            'borderRadius': '5px',
            'textAlign': 'center',
            'margin': '10px'
        }

        self.app.layout = html.Div([
            dbc.Container(
                [
                    html.H1('Branching Processes', id='page-title'),
                    html.Div([]),  # Empty div for top explanation texts
                    html.H2('Incidence Data'),
                    dbc.Row(
                        dbc.Col(
                            dcc.Graph(figure=bp.IncidenceNumberPlot().figure,
                                      id='data-fig'))),
                    dbc.Row(
                        [
                            dbc.Col(children=[
                                html.H6([
                                    'You can upload your own ',
                                    html.Span(
                                        'incidence data',
                                        id='inc-tooltip',
                                        style={
                                            'textDecoration': 'underline',
                                            'cursor': 'pointer'
                                        },
                                    ), ' here. It will appear as bars.'
                                ]),
                                dbc.Modal(
                                    self._inc_modal,
                                    id='inc_modal',
                                    size='xl',
                                ),
                                html.Div([
                                    'Data must be in the following column '
                                    'format: `Time`, `Incidence number`, '
                                    '`Imported Cases` (optional), '
                                    '`R_t` (true value of R, optional).'
                                ]),
                                dcc.Upload(
                                    id='upload-data',
                                    children=html.Div([
                                        'Drag and Drop or ',
                                        html.A('Select Files',
                                               style={
                                                   'text-decoration':
                                                   'underline'
                                               }), ' to upload your Incidence \
                                                    Number data.'
                                    ]),
                                    style=button_style,
                                    # Allow multiple files to be uploaded
                                    multiple=True),
                                html.Div(id='incidence-data-upload')
                            ]),
                            dbc.Col(children=[
                                html.H6([
                                    'You can upload your own ',
                                    html.Span('serial interval',
                                              id='si-tooltip',
                                              style={
                                                  'textDecoration':
                                                  'underline',
                                                  'cursor': 'pointer'
                                              }), ' here.'
                                ]),
                                dbc.Modal(
                                    self._si_modal,
                                    id='si_modal',
                                    size='lg',
                                ),
                                html.Div([
                                    'Data must contain one or more serial '
                                    'intervals to be used for constructing'
                                    ' the posterior distributions each '
                                    'included as a column.'
                                ]),
                                dcc.Upload(
                                    id='upload-interval',
                                    children=html.Div([
                                        'Drag and Drop or ',
                                        html.A('Select Files',
                                               style={
                                                   'text-decoration':
                                                   '\
                                                            underline'
                                               }), ' to upload your Serial \
                                                    Interval.'
                                    ]),
                                    style=button_style,
                                    # Allow multiple files to be uploaded
                                    multiple=True),
                                html.Div(id='ser-interval-upload')
                            ])
                        ],
                        align='center',
                    ),
                    html.H2('Plot of R values'),
                    html.Progress(id='progress_bar'),
                    html.Div(
                        id='first_run',  # see flip_first_run() in the app
                        children='True',
                        style={'display': 'none'}),
                    dbc.Row(
                        [
                            dbc.Col(children=dcc.Graph(
                                figure=bp.ReproductionNumberPlot().figure,
                                id='posterior-fig',
                                style={'display': 'block'})),
                            dbc.Col(self.update_sliders(), id='all-sliders')
                        ],
                        align='center',
                    ),
                    html.Div([]),  # Empty div for bottom text
                    html.Div(id='data_storage', style={'display': 'none'}),
                    html.Div(id='interval_storage', style={'display': 'none'}),
                    html.Div(id='posterior_storage', style={'display': 'none'})
                ],
                fluid=True),
            self.mathjax_script
        ])

        # Set the app index string for mathjax
        self.app.index_string = self.mathjax_html

        # Save the locations of texts from the layout
        self.main_text = self.app.layout.children[0].children[1].children
        self.collapsed_text = self.app.layout.children[0].children[-4].children
Ejemplo n.º 8
0
            dash_table.DataTable(
                id='table_results',
                data=df4.to_dict('records'),
                columns=[{'id': c, 'name': c} for c in df4.columns],
                style_cell={'textAlign': 'center', 'width': '100px', 'minWidth': '100px', 'maxWidth': '100px'},
                fixed_rows={'headers': True, 'data': 0},
                style_header={'fontWeight': 'bold'},
                style_table={'overflowX': 'auto'},
                editable=True
            ),

            html.Button('Send to My works', id='send-results-button', n_clicks=0,
                        style={'backgroundColor': 'rgba(255, 0, 0, 0.8)', 'color': 'white'}),
            html.Button('Send To Analysis', id='analysis-button', n_clicks=0,
                        style={'backgroundColor': 'rgba(255, 0, 0, 0.8)', 'color': 'white'}),
            html.Progress(id="progress", value="70", max="100")

        ], className='twelve columns'),

    ], className='twelve columns'),

    html.Div(id='stock-table', className='twelve columns'),

    html.Div(id='hidden-div', style={'display': 'none'}),
])


@app.callback(
    Output(component_id='hidden-div', component_property='children'),
    [Input(component_id='send-results-button', component_property='n_clicks'),
     Input(component_id='analysis-button', component_property='n_clicks')],
Ejemplo n.º 9
0
def serve_layout():
    session_id = str(uuid.uuid4())
    print(f"-------------------------------")
    print(f"New session: {session_id}")

    return html.Div([
        html.Div(session_id, id='session-id', style={'display': 'none'}),
        dcc.Interval(id='status-check', interval=2000, n_intervals=0),
        dcc.Interval(id='result-check', interval=5000, n_intervals=0),
        dcc.Store(id="node_status"),
        html.Div([
            html.Div(html.A(html.Img(src=app.get_asset_url("pyplan-logo.png"),
                                     id="pyplan-image",
                                     style={
                                         "height": "60px",
                                         "width": "auto",
                                     }),
                            href='https://www.pyplan.org',
                            target='_blank'),
                     className="threet columns"),
            html.H2("Pyplan/Dash Integration",
                    className="text-center six columns"),
            html.Div(html.A(html.Img(src=app.get_asset_url("dash-logo.png"),
                                     id="plotly-image",
                                     style={
                                         "height": "60px",
                                         "width": "auto",
                                     }),
                            href='https://plotly.com/dash/',
                            target='_blank'),
                     className="threet columns text-right"),
        ]),
        html.Div([
            html.Div([
                html.H4("Integrated Business Planning"),
                html.H5("Overview:"),
                html.
                P("This app is a commercial, operations and financial planning demo showcasing the integration of Pyplan with Dash.  Open the Input Panel to change parameters, select scenarios and check the results on the projected P&L Statement."
                  ),
                html.
                P("Explore the underlaying model logic by single clicking a node in the diagram and selecting the Code</> tab to inspect the Python code calculating business planning outcomes. Double click any node to run it an analyse its output as table and graph."
                  ),
            ],
                     className="twelve columns"),
        ],
                 className="row title"),
        html.Div([
            html.Progress(
                id='progress', value='0', max=30, style={"width": "100%"}),
            html.Div([
                html.Img(src=app.get_asset_url("wait_for_session.png"),
                         style={
                             "width": "100%",
                             "height": "auto",
                         })
            ],
                     id='pyplan-container',
                     style={'height': '800px'})
        ],
                 className="row"),
        html.H6('Profit and Loss Statement:'),
        html.Div([
            dcc.Loading(
                id="loading_charts",
                type="default",
                children=html.Div([
                    dash_table.DataTable(
                        id='pl_table',
                        fixed_rows={
                            "headers": True,
                            "data":
                            0
                        },
                        fixed_columns={
                            "headers": True,
                            "data":
                            1
                        },
                        style_table={
                            'width': '100%',
                        },
                        style_as_list_view=True,
                        column_selectable=False,
                        style_cell={
                            'padding':
                            '5px',
                            'fontSize':
                            '11px',
                            'fontFamily':
                            'Open Sans", HelveticaNeue, "Helvetica Neue", Helvetica, Arial, sans-serif'
                        },
                        style_header={
                            'backgroundColor': '#f2f2f2',
                            'fontWeight': 'bold'
                        },
                        style_data_conditional=[
                            {
                                'if': {
                                    'filter_query':
                                    '{Report index} eq "Revenue" or {Report index} eq "Operation Margin" or {Report index} eq "EBITDA" or {Report index} eq "Net Income" or {Report index} eq "EBIT" or {Report index} eq "Profit b/tax"',
                                },
                                'backgroundColor': '#f6f6f6',
                                'fontWeight': 'bold',
                            },
                            {
                                'if': {
                                    'column_id': 'Report index'
                                },
                                'backgroundColor': '#f2f2f2',
                                'textAlign': 'left'
                            },
                        ],
                        data=[],
                    ),
                    dcc.Graph(id="pl_chart",
                              figure={
                                  'data': [],
                                  'layout': {
                                      'height': 390
                                  }
                              })
                ]))
        ],
                 className="row box"),
    ],
                    className="container")
Ejemplo n.º 10
0
                             id='loader-trigger-1',
                             style={"display": "none"}),
                         html.Div(
                             id='loader-trigger-2',
                             style={"display": "none"}),
                         html.Div(
                             id='loader-trigger-3',
                             style={"display": "none"}),
                         html.Div(
                             id='loader-trigger-4',
                             style={"display": "none"}),
                         dcc.Markdown(
                             id='data_summary_filtered',
                             children=data_summary_filtered_md),
                         html.Progress(
                             id="selected_progress",
                             max=f"{len(df_original)}",
                             value=f"{len(df_original)}"),
                     ]),
     ]),
 html.Div(className="four columns pretty_container",
          children=[
              html.Label('Select pick-up hours'),
              dcc.RangeSlider(
                  id='hours',
                  value=[0, 23],
                  min=0,
                  max=23,
                  marks={i: str(i)
                         for i in range(0, 24, 3)}),
          ]),
 html.Div(className="four columns pretty_container",