Black Lives Matter. Please consider donating to Black Girls Code today.
Dash Enterprise delivers an incredible 21x cost savings 💸Download the e-book!

Basic Dash - Reading and Updating online data


I have a basic question about updating online data in my app.

To make short a long story, I’m have to access an online database every minute to update may dash visualization.

I’m starting the app reading a historical data and after that I’m trying to update that data using cache in a hide Div, appending data to that cache data frame (data_update function).

The problem is that the callback only accept one time the variable:

**SameInputOutputException** Traceback (most recent call last) **c:\Users\c3om\Documents\01 - WORK\02 - WORK\WellBotApp\wellbot_monitoring\** in
            [151] @app.callback(Output('cache-df','children'), 
            [152]                       [Input('update-df','n_intervals'), 
**----> [153]                      Input('cache-df','children')],)
            [154] def update_df (n, cache_df ,):
            [155]       dff = pd. read_json(cache_df )

 SameInputOutputException : Same output and input: cache-df.children

# ======= Initializing Data =======================================
df = (...) # historical data
monitor = monitoring_module.monitoring()
graphs   = graph_module.graphing(df)

# ======= Layout =============================================
app.layout = html.Div(
                        animate = True,
                        figure={'layout':{'plot_bgcolor': '#201f1f', 
                                                 'paper_bgcolor': '#201f1f',
                                                 'font': {'color': '#f3f5f4'}}}),
                style={'display': 'none'},
                id = "update-df",
                interval = AmostragemSegundos*1000,
                n_intervals = 0,),

# ======= Callbacks data update ==================================
@app.callback(Output('cache-df', 'children'),
              [Input('update-df', 'n_intervals'),
               Input('cache-df', 'children')],)

def update_df(n,cache_df):
    dff = pd.read_json(cache_df)
    df = monitor.data_update(dff , listaDeTagsDisponiveis)
    return df.to_json()

# ======= Callbacks live chart ====================================
@app.callback(Output('control-chart-live', 'figure'),
              [Input('update-df', 'n_intervals'),
               Input('cache-df', 'children'),],)

def upgrade_df(n, json_df):
    df = pd.read_json(json_df)
    control_graph = graphs.control_graph(df)
    return control_graph

Someone can help me?

1 Like

I would like to help, but I’m not sure what are you trying to accomplish. why do you want more than one time-variable as an input for your callback? the graph callback I guess you’re talking about.

Tnks @tyranus7. I’ve already fixed it. The problem was sometinhg related to the json structure.

Now, I’m using an strucutre with json.dumps

        datasets = {
                    'df_monitor': df_mon.to_json(orient='split', date_format='iso'),
                    'df_autoset': df_as.to_json(orient='split', date_format='iso'),
                    'df_control': df_ctr.to_json(orient='split', date_format='iso'),
                    'df_gain': df_gain.to_json(orient='split', date_format='iso'),
    return json.dumps(datasets)