# Plotly click events in streamlit

**URL:** <https://discuss.streamlit.io/t/plotly-click-events-in-streamlit/1419>\
**Category:** Using Streamlit\
**Tags:** plotly\
**Created:** [December 22, 2019, 8:35am UTC](https://discuss.streamlit.io/t/plotly-click-events-in-streamlit/1419 "2019-12-22T08:35:00Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![sandesh\_more](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/sandesh_more/32/934_2.png) [@sandesh\_more](https://discuss.streamlit.io/u/sandesh_more)\
**Post date:** [December 22, 2019, 8:35am UTC](https://discuss.streamlit.io/t/plotly-click-events-in-streamlit/1419/1 "2019-12-22T08:35:00Z")

</div>

I am using streamlit library for simple dashboard. Is it possible to use plotly click events in streamlit. Is there any other way to get click events on bar chart, scatter plots, etc, in streamlit?

The code that i tried :

import plotly.graph\_objects as go  
import streamlit as st  
import numpy as np

def update\_point(trace, points, state):  
print(trace, points, state)

def main():  
np.random.seed(1)  
x = np.random.rand(10)  
y = np.random.rand(10)  
f = go.FigureWidget([go.Scatter(x=x, y=y)])  
s = f.data[0]

```
st.plotly_chart(f)
s.on_click(update_point)

```

if **name** == ‘ **main** ’:  
main()

---

<div class="post-metadata">

**Author:** ![Marc](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/marc/32/602_2.png) [@Marc](https://discuss.streamlit.io/u/Marc)\
**Post date:** [December 23, 2019, 5:05am UTC](https://discuss.streamlit.io/t/plotly-click-events-in-streamlit/1419/2 "2019-12-23T05:05:51Z")

</div>

Hi @sandesh_more

That kind of interactivity is currently not supported. See [https://github.com/streamlit/streamlit/issues/455](https://github.com/streamlit/streamlit/issues/455)

---

<div class="post-metadata">

**Author:** ![sandesh\_more](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/sandesh_more/32/934_2.png) [@sandesh\_more](https://discuss.streamlit.io/u/sandesh_more)\
**Post date:** [December 23, 2019, 6:02am UTC](https://discuss.streamlit.io/t/plotly-click-events-in-streamlit/1419/3 "2019-12-23T06:02:35Z")

</div>

Thanks for the reply.

---

<div class="post-metadata">

**Author:** ![jdc89](https://avatars.discourse-cdn.com/v4/letter/j/cc9497/32.png) [@jdc89](https://discuss.streamlit.io/u/jdc89)\
**Post date:** [February 22, 2021, 8:37am UTC](https://discuss.streamlit.io/t/plotly-click-events-in-streamlit/1419/4 "2021-02-22T08:37:58Z")

</div>

Hi, I see this thread was created in 2019, I just wanted to know if there have been updates on this matter? i.e. using go.FigureWidget and get outputs from graph selection?

---

<div class="post-metadata">

**Author:** ![akor128](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/akor128/32/4159_2.png) [@akor128](https://discuss.streamlit.io/u/akor128)\
**Post date:** [May 3, 2021, 6:02pm UTC](https://discuss.streamlit.io/t/plotly-click-events-in-streamlit/1419/5 "2021-05-03T18:02:03Z")

</div>

New functionality!

> **[null-jones/streamlit-plotly-events](https://github.com/null-jones/streamlit-plotly-events)**
>
> Streamlit component that allows Plotly events to bubble back up to streamlit. Makes Plotly charts interactive!

---

<div class="post-metadata">

**Author:** ![Andrew\_Holoska](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/andrew_holoska/32/724_2.png) [@Andrew\_Holoska](https://discuss.streamlit.io/u/Andrew_Holoska)\
**Post date:** [September 7, 2021, 10:29pm UTC](https://discuss.streamlit.io/t/plotly-click-events-in-streamlit/1419/6 "2021-09-07T22:29:20Z")

</div>

How can I return the min, max X values from a selection?

---

<div class="post-metadata">

**Author:** ![Anaqi\_Afendi](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/anaqi_afendi/32/5508_2.png) [@Anaqi\_Afendi](https://discuss.streamlit.io/u/Anaqi_Afendi)\
**Post date:** [February 16, 2022, 9:56pm UTC](https://discuss.streamlit.io/t/plotly-click-events-in-streamlit/1419/7 "2022-02-16T21:56:23Z")

</div>

Does this support the `use_container_width` argument when displaying the figure?

---

<div class="post-metadata">

**Author:** ![Hasnain](https://avatars.discourse-cdn.com/v4/letter/h/ea666f/32.png) [@Hasnain](https://discuss.streamlit.io/u/Hasnain)\
**Post date:** [April 2, 2022, 9:25am UTC](https://discuss.streamlit.io/t/plotly-click-events-in-streamlit/1419/8 "2022-04-02T09:25:59Z")

</div>

Hi, I have added this event somewhere in between my Streamlit dashboard for a specific visual. The code would not run beyond that specific visual in the first go until I click on it and create a streamlit event, only then the rest of the visuals would get displayed. Can anyone help with it?

---

<div class="post-metadata">

**Author:** ![R\_D](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/r_d/32/15030_2.png) [@R\_D](https://discuss.streamlit.io/u/R_D)\
**Post date:** [September 14, 2022, 9:29am UTC](https://discuss.streamlit.io/t/plotly-click-events-in-streamlit/1419/9 "2022-09-14T09:29:30Z")

</div>

> [@Anaqi\_Afendi](#):
>
> `use_container_width`

Does it support

> use\_container\_width

?

---

<div class="post-metadata">

**Author:** ![snehankekre](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/snehankekre/32/6504_2.png) [@snehankekre](https://discuss.streamlit.io/u/snehankekre)\
**Post date:** [September 14, 2022, 12:23pm UTC](https://discuss.streamlit.io/t/plotly-click-events-in-streamlit/1419/10 "2022-09-14T12:23:43Z")

</div>

> [@R\_D](#):
>
> Does it support
> 
> > use\_container\_width
> 
> ?

Yes, `st.plotly_chart` contains a boolean `use_container_width` parameter:

> **[st.plotly\_chart - Streamlit Docs](https://docs.streamlit.io/library/api-reference/charts/st.plotly_chart)**
>
> st.plotly\_chart displays an interactive Plotly chart.

---

<div class="post-metadata">

**Author:** ![R\_D](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/r_d/32/15030_2.png) [@R\_D](https://discuss.streamlit.io/u/R_D)\
**Post date:** [December 19, 2022, 11:11am UTC](https://discuss.streamlit.io/t/plotly-click-events-in-streamlit/1419/11 "2022-12-19T11:11:11Z")

</div>

This changes the theme of any plotly chart to black and white. Any thoughts on how to solve this?

---

<div class="post-metadata">

**Author:** ![willhuang](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/willhuang/32/8445_2.png) [@willhuang](https://discuss.streamlit.io/u/willhuang)\
**Post date:** [December 19, 2022, 5:51pm UTC](https://discuss.streamlit.io/t/plotly-click-events-in-streamlit/1419/12 "2022-12-19T17:51:42Z")

</div>

@R_D , can you explain your problem more? Maybe post some screenshots and some code?

---

<div class="post-metadata">

**Author:** ![Kevin1](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/kevin1/32/21709_2.png) [@Kevin1](https://discuss.streamlit.io/u/Kevin1)\
**Post date:** [January 9, 2023, 10:51pm UTC](https://discuss.streamlit.io/t/plotly-click-events-in-streamlit/1419/13 "2023-01-09T22:51:59Z")

</div>

Hey, ran into the same issue and figured out what’s wrong. Looks like the recent streamlit update is trying to managing plotly’s color. As a result all the color will show up as black unless you use streamlit’s plotly\_chart method.

Here is the thread talking about the exact same issue.

> [@Streamlit overrides colours of plotly chart](https://discuss.streamlit.io/t/streamlit-overrides-colours-of-plotly-chart/34943):
>
> Summary Ok, so the issue is the following: since version 1.15.2, Streamlit seems to override colours of any created plotly figure, which breaks its rendering when its not done via Streamlit itself (for example, fig.to\_html()) Consider the following code: import streamlit as st import pandas as pd import numpy as np import plotly.express as px x\_axis = list(range(4))\*2 x\_axis.sort() data = np.array([["a", "b"]\*4, x\_axis, [2, 4, 3, 5, 7, 5, 8, 6]]).transpose() df = pd.DataFrame(columns=["cat\_…

Hopefully streamlit will fix this. In the mean time if you explicit set plotly line color (might have to use plotly’s graph\_object interface) the color will appear correctly.

---

<div class="post-metadata">

**Author:** ![willhuang](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/willhuang/32/8445_2.png) [@willhuang](https://discuss.streamlit.io/u/willhuang)\
**Post date:** [January 11, 2023, 6:28pm UTC](https://discuss.streamlit.io/t/plotly-click-events-in-streamlit/1419/14 "2023-01-11T18:28:39Z")

</div>

Hi @Kevin1 ,

Thanks for pointing out this out. I hadn’t noticed this and I wish I had earlier.

If you wish to change the colors to the plotly colors instead of the black,

you can put this in your script:

```auto
import plotly.io as pio
pio.templates.default = "plotly"

```

You can test this out by changing the colors in the underlying script to whatever. Right now in the script, they are streamlit colors.

```auto
import plotly.io as pio
import streamlit as st
import plotly.express as px

pio.templates.default = "plotly"

df = px.data.tips()
fig = px.scatter(
    df,
    x="total_bill",
    y="tip",
    color="day",
    color_discrete_sequence=[
        "#0068c9",
        "#83c9ff",
        "#ff2b2b",
        "#ffabab",
        "#29b09d",
        "#7defa1",
        "#ff8700",
        "#ffd16a",
        "#6d3fc0",
        "#d5dae5",
    ],
    title="streamlit colors",
)
st.plotly_chart(fig)

```

---

<div class="post-metadata">

**Author:** ![Arushi\_Agarwal](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/arushi_agarwal/32/22211_2.png) [@Arushi\_Agarwal](https://discuss.streamlit.io/u/Arushi_Agarwal)\
**Post date:** [January 24, 2023, 3:53pm UTC](https://discuss.streamlit.io/t/plotly-click-events-in-streamlit/1419/15 "2023-01-24T15:53:08Z")

</div>

Hi, This discussion was very helpful! Thanks all!  
I have a quick question, I am using Plotly-events for capturing user selection from a bar chart but I want to reset this selection to null when my streamlit dashboard reloads. How can I make this happen? Thanks.

---

<div class="post-metadata">

**Author:** ![Ran\_Bernstein](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/ran_bernstein/32/30997_2.png) [@Ran\_Bernstein](https://discuss.streamlit.io/u/Ran_Bernstein)\
**Post date:** [August 21, 2023, 12:50pm UTC](https://discuss.streamlit.io/t/plotly-click-events-in-streamlit/1419/16 "2023-08-21T12:50:10Z")

</div>

> [@Marc](#):
>
> [Ability to accept input from Charts, Tables, etc. · Issue #455 · streamlit/streamlit · GitHub](https://github.com/streamlit/streamlit/issues/455)

Hi, any update regarding getting the clicked point from a plotly chart?  
The work around of using plotly-events doesn’t work well after streamlit 1.12.0.  
Thanks!

---

<div class="post-metadata">

**Author:** ![Ayanjit\_Chatterjee](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/ayanjit_chatterjee/32/28427_2.png) [@Ayanjit\_Chatterjee](https://discuss.streamlit.io/u/Ayanjit_Chatterjee)\
**Post date:** [August 31, 2023, 7:10pm UTC](https://discuss.streamlit.io/t/plotly-click-events-in-streamlit/1419/17 "2023-08-31T19:10:14Z")

</div>

I am also facing problems regarding this, did you find any fixes?

---

<div class="post-metadata">

**Author:** ![Mroma](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/mroma/32/39897_2.png) [@Mroma](https://discuss.streamlit.io/u/Mroma)\
**Post date:** [March 9, 2024, 8:30pm UTC](https://discuss.streamlit.io/t/plotly-click-events-in-streamlit/1419/18 "2024-03-09T20:30:50Z")

</div>

This is no longer working with the latest updates

---

<div class="post-metadata">

**Author:** ![shkarlsson](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/shkarlsson/32/38942_2.png) [@shkarlsson](https://discuss.streamlit.io/u/shkarlsson)\
**Post date:** [August 7, 2024, 2:13pm UTC](https://discuss.streamlit.io/t/plotly-click-events-in-streamlit/1419/19 "2024-08-07T14:13:57Z")

</div>

[I believe they have fixed this…](https://github.com/streamlit/streamlit/issues/455#issuecomment-2111149108)
