TypeError: unhashable type: 'list' for dcc.store data

Hi. I am new to dash and plotly. Basically what my code is trying to do is take the dataframe that is stored in a dictionary and place in dcc.store data. is there a reason I am getting an TypeError for dcc.store data?
Here is my code. The error is in the second callback.
Callbacks:

    def upload_bcf_alert(data: Any) -> Any:
        if ctx.triggered_id == "stored-bcf-data" and data:
            return "Successful BCF Data Upload", True
        elif (
                ctx.triggered_id == "stored-bcf-data"
                and data is not None
                and len(data) == 0
        ):
            return "BCF Data not uploaded successfully", True
        else:
            return no_update

    @app.callback(
        Output("bcf-dropdown", "options"),
        Input("upload-bcf-data", "contents")
    )
    def bcf_dropdown(contents: str) -> Any | list:
        """
        """
        if contents is None:
            raise PreventUpdate
        bcf_tabs, bcf_df_dict = adf_parser(contents)
        return bcf_tabs


    @app.callback(
        Output("stored-bcf-data", "data"),
        Input("bcf-dropdown", "value"),
        Input("upload-bcf-data", "contents")
    )
    def bcf_tab_output(value: str, contents: str):
        
        if contents is None:
            raise PreventUpdate
        if value is None:
            raise PreventUpdate
        bcf_tabs, bcf_dict = bcf_parser(contents)
        bcf_select_df = bcf_dict[value]

        return bcf_select_df.to_dict("records")

dash function that is called.

def bcf_parser(contents: str) -> object:

    content_type, content_string = contents.split(",")
    decoded = base64.b64decode(content_string)
    bcf_obj = pad.BCFParser(io.BytesIO(decoded))
    bcf_tabs = bcf_obj.bcf_sheetnames
    bcf_df_dict = bcf_obj.bcf_dataframes
    return bcf_tabs, bcf_df_dict

This is probably an easy fix…but I just can’t seem to understand why I am getting this:
**Callback error updating stored-adf-data.data
TypeError: unhashable type: ‘list’
**

BCFParser is a whole class… and basically it takes an excel file that has multiple sheets and places those sheets in dataframes and returns those dataframes as values in a dictionary.

dcc.Stores require JSON data, you need to json.dumps when you return, and json.loads when you have the Store as Input or State: dcc Store

1 Like

So you are saying I should do this:

@app.callback(
        Output("stored-bcf-data", "data"),
        Input("bcf-dropdown", "value"),
        Input("upload-bcf-data", "contents")
    )
    def bcf_tab_output(value: str, contents: str):
        
        if contents is None:
            raise PreventUpdate
        if value is None:
            raise PreventUpdate
        bcf_tabs, bcf_dict = bcf_parser(contents)
        bcf_select_df = bcf_dict[value]

        return json.dumps(bcf_select_df.to_dict("records"))

I tried this. it didn’t work for me… :face_with_diagonal_mouth:
I thought dcc.store could take a list as a return value for data storage? why do the other callback work and bdf_tab_output doesn’t? the way I returned the dataframe, bcf_select_df.to_dict('records), this is used in a lot of different tutorials.

sorry for the oversight, you can indeed return dictionaries like this.
One Idea might be that your dropdown is set to multi=True and value is a list then.
Calling bcf_dict[value] would then raise this TypeError.

ok. I changed muli to false. It definitely works!!! Thank you!!! I appreciate it. :pray: :clap:

1 Like