Quantcast
Channel: 🎛️ Dash - Plotly Community Forum
Viewing all articles
Browse latest Browse all 6271

How to save and access multiple data frames from dcc.Store in plotly dash

$
0
0

All,

I am getting into plotly dash and have got some great guidance from the documentation and the stack overflow community. Really thankful for that. Ran into one question, which I am not sure is clear in the documentation, so it would be great if anybody from the community can offer some guidance on. Here is what I have so far:

# Import required libraries
import dash
import math
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output, State, MATCH


# App Begins
app = dash.Dash(
    __name__, meta_tags=[{"name": "viewport", "content": "width=device-width"}],
)
app.title = "Tool"
server = app.server

# Create global chart template
mapbox_access_token = "pk.eyJ1IjoicGxvdGx5bWFwYm94IiwiYSI6ImNrOWJqb2F4djBnMjEzbG50amg0dnJieG4ifQ.Zme1-Uzoi75IaFbieBDl3A"

layout = dict(
    autosize=True,
    automargin=True,
    margin=dict(l=30, r=30, b=20, t=40),
    hovermode="closest",
    plot_bgcolor="#F9F9F9",
    paper_bgcolor="#F9F9F9",
    legend=dict(font=dict(size=10), orientation="h"),
    title="Satellite Overview",
    mapbox=dict(
        accesstoken=mapbox_access_token,
        style="light",
        center=dict(lon=-78.05, lat=42.54),
        zoom=7,
    ),
)

# Create app layout
app.layout = html.Div(
    [
        dcc.Store(id="aggregate_data"),
        # empty Div to trigger javascript file for graph resizing
        html.Div(id="output-clientside"),
        html.Div(
            [
                html.Div(
                    [
                        html.Img(
                            src=app.get_asset_url("dash-logo.png"),
                            id="plotly-image",
                            style={
                                "height": "60px",
                                "width": "auto",
                                "margin-bottom": "25px",
                            },
                        )
                    ],
                    className="one-third column",
                ),
                html.Div(
                    [
                        html.Div(
                            [
                                html.H3(
                                    "Dash Tool",
                                    style={"margin-bottom": "0px"},
                                ),
                            ]
                        )
                    ],
                    className="one-half column",
                    id="title",
                ),
            ],
            id="header",
            className="row flex-display",
            style={"margin-bottom": "25px"},
        ),
        html.Div(
            [
                html.Div(
                    [
                        html.P("Quantity 1:", className="control_label"),
                        dcc.Input(
                           id="quantity_1",
                           type="number",
                           placeholder=33.
                        ),
                        html.P("Quantity 2:", className="control_label"),
                        dcc.Input(
                            id="quantity_2",
                            type="number",
                            placeholder=-115.
                        ),
                        html.P("Number of Drop Downs:", className="control_label"),
                        dcc.Slider(
                            id="drop_downs",
                            min=2,
                            max=10,
                            value=2,
                            step=1.0,
                            className="dcc_control",
                        ),
                        html.P("Load Inputs:", className="control_label"),
                        dcc.Checklist(
                            id='sources_flag',
                            options=[
                                {'label': 'Yes', 'value': 'Y'},
                            ],
                            value=['Y'],
                            labelStyle={'display': 'inline-block'}
                        ),
                        html.Div(id='source_dropdown_container', children=[]),
                        html.Div(id='source_dropdown_container_output'),
                        html.Div(id='source_file_container', children=[]),
                        html.Div(id='source_file_container_output'),
                    ],
                    className="pretty_container four columns",
                    id="cross-filter-options",
                ),
            ],
            className="row flex-display",
        ),
    ],
    id="mainContainer",
    style={"display": "flex", "flex-direction": "column"},
)


# Create callbacks
@app.callback(
    Output(component_id='source_dropdown_container_output', component_property='children'),
    [
        Input(component_id='drop_downs', component_property='value'),
        Input(component_id='sources_flag', component_property='value'),
    ]
)
def update_source_dropdowns(value, value_1):
    """Controls the number of drop-downs available to choose sources"""
    print("cb", value, value_1)
    if value_1 == ['Y']:
        children = []
        for i in range(0, value):
            new_dropdown = html.Div(
                dcc.Upload(
                    id={'index': f'''meteo_source_dropdown_{str(value_1)}''', 'type': 'dynamic-dropdown'},
                    children=html.Div([
                        (html.Button('Upload File')),
                    ])
                )
            )
            children.append(new_dropdown)
        print(children)
        print(type(children))
        return children


if __name__ == '__main__':
    app.run_server(debug=True)

When the user clicks each file upload button and uploads a new file (most likely a csv), how can I store and then retrieve them on an as needed basis without losing their identity from a dcc.Store? What I mean is, if a dataset was uploaded with the first button click, while retrieving that data from the dcc.Store, I would want to know which click that data set is associated with. Thanks a lot in advance for any help.

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 6271

Latest Images

Trending Articles



Latest Images