コード例 #1
0
ファイル: test_download_file.py プロジェクト: plotly/dash
def test_dlfi001_download_file(dash_dcc):
    filename = "chuck.jpg"
    asset_folder = os.path.join(os.path.dirname(__file__), "download-assets")
    # Create app.
    app = Dash(__name__, prevent_initial_callbacks=True)
    app.layout = html.Div(
        [html.Button("Click", id="btn"),
         dcc.Download(id="download")])

    @app.callback(Output("download", "data"), Input("btn", "n_clicks"))
    def download(_):
        return dcc.send_file(os.path.join(asset_folder, filename))

    dash_dcc.start_server(app)

    # Check that there is nothing before clicking
    fp = os.path.join(dash_dcc.download_path, filename)
    assert not os.path.isfile(fp)

    dash_dcc.find_element("#btn").click()

    # Check that a file has been download, and that it's content matches the original.
    until(lambda: os.path.exists(fp), 10)
    with open(fp, "rb") as f:
        content = f.read()
    with open(os.path.join(asset_folder, filename), "rb") as f:
        original = f.read()
    assert content == original

    assert dash_dcc.get_logs() == []
コード例 #2
0
ファイル: test_download.py プロジェクト: plotly/dash
def test_dltx001_download_text(dash_dcc):
    text = "Hello, world!"
    filename = "hello.txt"
    # Create app.
    app = Dash(__name__, prevent_initial_callbacks=True)
    app.layout = html.Div(
        [html.Button("Click", id="btn"),
         dcc.Download(id="download")])

    @app.callback(Output("download", "data"), Input("btn", "n_clicks"))
    def download(_):
        return dcc.send_string(text, filename)

    dash_dcc.start_server(app)

    # Check that there is nothing before clicking
    fp = os.path.join(dash_dcc.download_path, filename)
    assert not os.path.isfile(fp)

    dash_dcc.find_element("#btn").click()

    # Check that a file has been download, and that it's content matches the original text.
    until(lambda: os.path.exists(fp), 10)
    with open(fp, "r") as f:
        content = f.read()
    assert content == text

    assert dash_dcc.get_logs() == []
コード例 #3
0
ファイル: component.py プロジェクト: Raiytak/Comptes
 def downloadButton(cls):
     download_div = html.Div(
         [
             html.Button("Download Excel", id=cls.download_excel_button, n_clicks=0),
             dcc.Download(id=cls.download_excel),
         ]
     )
     return download_div
コード例 #4
0
 def _add_plotting_col(self) -> dbc.Col:
     """Add column with plots and tables. It is placed on the right side.
     """
     return dbc.Col(
         id="col-plotting-area",
         children=[
             dbc.Row(  # Passed / failed tests
                 id="row-graph-passed",
                 class_name="g-0 p-2",
                 children=[
                     dcc.Loading(children=[
                         dcc.Graph(id="graph-passed",
                                   figure=self._default_fig_passed)
                     ])
                 ]),
             dbc.Row(  # Duration
                 id="row-graph-duration",
                 class_name="g-0 p-2",
                 children=[
                     dcc.Loading(children=[
                         dcc.Graph(id="graph-duration",
                                   figure=self._default_fig_duration)
                     ])
                 ]),
             dbc.Row(
                 class_name="g-0 p-2",
                 align="center",
                 justify="start",
                 children=[
                     dbc.Col(  # Download
                         width=2,
                         children=[
                             dcc.Loading(children=[
                                 dbc.Button(id="btn-download-data",
                                            children=self._show_tooltip(
                                                "help-download",
                                                "Download Data"),
                                            class_name="me-1",
                                            color="info"),
                                 dcc.Download(id="download-data")
                             ]),
                         ]),
                     dbc.Col(  # Show URL
                         width=10,
                         children=[
                             dbc.Card(id="card-url",
                                      body=True,
                                      class_name="gy-2 p-0",
                                      children=[]),
                         ])
                 ])
         ],
         width=9,
     )
コード例 #5
0
def clientside_stores(get_uuid: Callable) -> html.Div:
    """Contains the clientside stores"""
    return html.Div(children=[
        dcc.Store(id=get_uuid("selections"), storage_type="session"),
        dcc.Store(id=get_uuid("page-selected"), storage_type="session"),
        dcc.Store(id=get_uuid("voldist-page-selected"),
                  storage_type="session"),
        dcc.Store(id=get_uuid("initial-load-info"), storage_type="memory"),
        html.Div(
            style={"display": "none"},
            children=dcc.Download(id=get_uuid("download-dataframe")),
        ),
    ])
コード例 #6
0
def get_standard_download_all_button(button_id,
                                     download_id,
                                     progress_id=None,
                                     collapse_id=None):
    """Return a standard download button.
    """
    if progress_id and collapse_id:
        button = html.Div([
            html.Div([
                dbc.Collapse(dbc.Row([html.Progress(id=progress_id)]),
                             id=collapse_id,
                             is_open=False),
                dcc.Download(id=download_id),
            ]),
            dbc.Row([
                html.Button(id=button_id, children="Download All In Table"),
            ])
        ])
    else:
        button = html.Div([
            html.Div([
                dcc.Download(id=download_id),
            ],
                     style={'display': 'inline-block'}),
            html.Button(id=button_id,
                        children="Download All In Table",
                        style={
                            'padding': "5px 15px",
                            "borderRadius": "7px",
                            'backgroundColor': "#0c6efd",
                            'color': "white",
                            'border': 'none'
                        }),
        ],
                          style={'float': 'right'})
    return button
コード例 #7
0
def test_dldf001_download_dataframe(fmt, dash_dcc):
    df = pd.DataFrame({
        "a": [1, 2, 3, 4],
        "b": [2, 1, 5, 6],
        "c": ["x", "x", "y", "y"]
    })
    reader = getattr(pd, "read_{}".format(fmt))  # e.g. read_csv
    writer = getattr(df, "to_{}".format(fmt))  # e.g. to_csv
    filename = "df.{}".format(fmt)
    # Create app.
    app = Dash(__name__, prevent_initial_callbacks=True)
    app.layout = html.Div(
        [html.Button("Click me", id="btn"),
         dcc.Download(id="download")])

    @app.callback(Output("download", "data"), Input("btn", "n_clicks"))
    def download(_):
        # For csv and html, the index must be removed to preserve the structure.
        if fmt in ["csv", "html", "excel"]:
            return dcc.send_data_frame(writer, filename, index=False)
        # For csv and html, the index must be removed to preserve the structure.
        if fmt in ["stata"]:
            a = dcc.send_data_frame(writer, filename, write_index=False)
            return a
        # For other formats, no modifications are needed.
        return dcc.send_data_frame(writer, filename)

    dash_dcc.start_server(app)

    # Check that there is nothing before clicking
    fp = os.path.join(dash_dcc.download_path, filename)
    assert not os.path.isfile(fp)

    dash_dcc.find_element("#btn").click()

    # Check that a file has been download, and that it's content matches the original data frame.
    until(lambda: os.path.exists(fp), 10)
    df_download = reader(fp)
    if isinstance(df_download, list):
        df_download = df_download[0]
    # For stata data, pandas equals fails. Hence, a custom equals is used instead.
    assert df.columns.equals(df_download.columns)
    assert df.index.equals(df_download.index)
    np.testing.assert_array_equal(df.values, df_download.values)

    assert dash_dcc.get_logs() == []
コード例 #8
0
ファイル: data_explorer.py プロジェクト: quuhua911/NeMo
                    'textAlign': 'left'
                },
                style_header={'color': 'text-primary'},
                css=[
                    {
                        'selector': '.dash-filter--case',
                        'rule': 'display: none'
                    },
                ],
            ), ),
        class_name='m-2',
    ),
    dbc.Row(
        dbc.Col([
            html.Button('Download Vocabulary', id='btn_csv'),
            dcc.Download(id='download-vocab-csv'),
        ]), ),
]


@app.callback(
    Output('download-vocab-csv', 'data'),
    [
        Input('btn_csv', 'n_clicks'),
        State('wordstable', 'sort_by'),
        State('wordstable', 'filter_query')
    ],
    prevent_initial_call=True,
)
def download_vocabulary(n_clicks, sort_by, filter_query):
    vocabulary_view = vocabulary
    dcc.Link('Global Caseload and Mortality', href='/'),
    html.Br(),
    html.Br(),
    dcc.Link('Cases and Deaths By Country', href='/compare'),
    html.Br(),
    html.Br(),
    dcc.Link('Predictions', href='/predict'),
    html.Br(),
    html.Br(),
    dcc.Link('Kenya Vaccinations by County/Region', href='/vaccines'),
    html.Br(),
    html.P('Download the latest COVID-19  report by clicking the button below;',style={'textAlign':'center'}),
    html.Br(),
    html.Div(
    [html.Button("Download Report", id="btn_doc"),
    dcc.Download(id="download-doc")],style={'textAlign':'center'}),
    html.Br(),
    html.P('To have the report automatically sent to you via email, enter your email address below then click Submit Email.',style={'textAlign':'center'}),
    html.Div([
    html.Div(dcc.Input(id='input-on-submit', type='email',value=""),style={'textAlign':'center'}),
    html.Br(),
    html.Div(
    html.Button('Submit Email', id='submit-val', n_clicks=0),style={'textAlign':'center'}),
    html.Br(),
    html.Div(id='email-string',style={'textAlign':'center'})
    ])
])

# Page 3, for predictions
page_3_layout = html.Div([
    html.H1('Predict Cases and Deaths by Country',
コード例 #10
0
ファイル: index.py プロジェクト: pernaletec/diogenet_py
                        3: '3',
                        4: '4',
                        5: '5',
                        6: '6',
                        7: '7',
                        8: '8',
                        9: '9',
                        10: '10',
                    },
                    value=[4, 6]),
    html.H6('Download travel edges graph data', className="mt-5 mb-3"),
    dbc.Button("Download Data",
               id="btn_csv_map",
               style={'backgroundColor': '#716450'},
               className="ml-3"),
    dcc.Download(id="download-dataframe-csv-map"),
]

tabs = dcc.Tabs(id='tabs_map',
                value='map_maps',
                parent_className='custom-tabs',
                className='custom-tabs-container',
                children=[
                    dcc.Tab(label='Map',
                            value='map_maps',
                            className='custom-tab',
                            selected_className='custom-tab--selected'),
                    dcc.Tab(label='Metrics',
                            value='map_metrics',
                            className='custom-tab',
                            selected_className='custom-tab--selected'),
コード例 #11
0
                            dcc.Graph(id="ecdf-plot", config=plot_config)
                        ],
                    ),
                    # Summary statistics table
                    html.Div(
                        className="stats-table",
                        children=[html.Table(id="summary-stats")],
                    ),
                    dcc.Store(id="sample-store"),
                    # Sample download button
                    html.Button(
                        "Download sample",
                        id="sample-download-button",
                        className="custom-button",
                    ),
                    dcc.Download(id="download-sample"),
                ],
            ),
        ],
    ),
])


@app.callback(
    Output("distribution-param-sliders", "children"),
    Input("current-distribution", "value"),
)
def create_parameter_sliders(distribution: str) -> tuple:
    """Get the parameter label(s) & slider(s) for parameter(s) of the selected
    distribution.
コード例 #12
0
def get_download_local_file_button(pathname):
    button_text = "Download: " + pathname.split('/')[-1]
    fake_button = html.Button(button_text,
                              key=pathname,
                              id="btn-download-file")
    return html.Div([fake_button, dcc.Download(id="download-file")])
コード例 #13
0
                )
            ]),
])
            ]),
        html.Div([
                html.Hr(),
                html.Div([
                    html.Button('Update Grid', id='update-grid-button', n_clicks=0,
                                style={'marginLeft': '5px'},className='button'),
                    html.Button('Select All', id='select-all-button', n_clicks=0,
                                style={'marginLeft': '5px'},className='button'),
                    html.Button('Deselect All', id='deselect-all-button', n_clicks=0,
                                style={'marginLeft': '5px'},className='button'),
                    html.Button('Export All', id='export-all-button', n_clicks=0,
                                style={'marginLeft': '5px'},className='button'),
                    dcc.Download(id='datatable-download'),
                    html.Button('Export Filtered', id='export-filtered-button',n_clicks=0,
                                style={'marginLeft': '5px'},className='button'),
                    dcc.Download(id='datatable-filtered-download'),
                    html.Button('Add Row', id='add-row-button', n_clicks=0,
                                style={'marginLeft': '5px'}, className='button'),
                    html.Button('Delete Row(s)', id='delete-rows-button', n_clicks=0,
                                style={'marginLeft': '5px'}, className='button'),
                ]),
        ],
            style={'width': '100%'}
        ),
        dcc.Loading(id='loading-icon-upload',
                    children=[
                        html.Div([],
                                 style={