Get selected data from plotly parallel coordinates plot

Hello!

I am running an app locally (streamlit 1.32.2, python 3.10.11), and I have a plotly parallel coordinates plot. An example:

import plotly.graph_objects as go
import streamlit as st
import pandas as pd

df = pd.read_csv("https://raw.githubusercontent.com/bcdunbar/datasets/master/iris.csv")

fig = go.Figure(data=
    go.Parcoords(
        line = dict(color = df['species_id'],
                   colorscale = [[0,'purple'],[0.5,'lightseagreen'],[1,'gold']]),
        dimensions = list([
            dict(range = [0,8],
                constraintrange = [4,8],
                label = 'Sepal Length', values = df['sepal_length']),
            dict(range = [0,8],
                label = 'Sepal Width', values = df['sepal_width']),
            dict(range = [0,8],
                label = 'Petal Length', values = df['petal_length']),
            dict(range = [0,8],
                label = 'Petal Width', values = df['petal_width'])
        ])
    )
)

fig.update_layout(
    plot_bgcolor = 'wPreformatted texthite',
    paper_bgcolor = 'white'
)

fig.show()
st.plotly_chart(fig, use_container_width=True)

On the graph, I can select certain ranges for my parameters, and the lines corresponding to the ranges are highlighted. How can I extract this data to display in a dataframe or follow-up plot? I know it is possible with callbacks when using dash, but I was not able to find any solution for streamlit, so I decided to make a post.

Chart selections have just been introduced in Streamlit 1.35.0.

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