TypeError: _update_session_state() missing 1 required positional argument: 'df'

when Itrying to pass some parameters into a callback function I got an error :

import streamlit as st
import plotly.express as px

def _update_session_state(df):
    st.dataframe(df)

def plot():
    totot="sfsdfg"
    df = px.data.iris()
    fig = px.scatter(
        df,
        x="sepal_width",
        y="sepal_length",
        color="species",
        size="petal_length",
        hover_data=["petal_width"],
    )
    event=st.plotly_chart(fig, 
    key="plotgraph",on_select=_update_session_state,args=(df,))
    event

plot()

when I try to select a bubble I got this error :

TypeError: _update_session_state() missing 1 required positional argument: ‘df’

any idea please ?

You cannot pass any arguments to the on_select callback. Try this instead:

on_select=lambda: _update_session_state(df)
1 Like

thanks

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.