Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/streamlit_plotly_events/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import streamlit.components.v1 as components
from json import loads
from json import loads, dumps

# Create a _RELEASE constant. We'll set this to False while we're developing
# the component, and True when we're ready to package and distribute it.
Expand Down Expand Up @@ -51,6 +51,7 @@ def plotly_events(
hover_event=False,
override_height=450,
override_width="100%",
config={},
key=None,
):
"""Create a new instance of "plotly_events".
Expand All @@ -69,6 +70,8 @@ def plotly_events(
Integer to override component height. Defaults to 450 (px)
override_width: string, default: '100%'
String (or integer) to override width. Defaults to 100% (whole width of iframe)
config: dictionary, default: {}
Plotly config dictionary. Defaults to {}
key: str or None
An optional key that uniquely identifies this component. If this is
None, and the component's arguments are changed, the component will
Expand Down Expand Up @@ -98,6 +101,7 @@ def plotly_events(
plot_obj=plot_fig.to_json(),
override_height=override_height,
override_width=override_width,
config=dumps(config),
key=key,
click_event=click_event,
select_event=select_event,
Expand All @@ -121,7 +125,7 @@ def plotly_events(
st.subheader("Plotly Line Chart")
fig = px.line(x=[0, 1, 2, 3], y=[0, 1, 2, 3])
plot_name_holder = st.empty()
clickedPoint = plotly_events(fig, key="line")
clickedPoint = plotly_events(fig, key="line", config={"displayModeBar": True})
plot_name_holder.write(f"Clicked Point: {clickedPoint}")

# Here we add columns to check auto-resize/etc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class StreamlitPlotlyEventsComponent extends StreamlitComponentBase {
public render = (): ReactNode => {
// Pull Plotly object from args and parse
const plot_obj = JSON.parse(this.props.args["plot_obj"]);
const config = JSON.parse(this.props.args["config"]);
const override_height = this.props.args["override_height"];
const override_width = this.props.args["override_width"];

Expand All @@ -23,7 +24,7 @@ class StreamlitPlotlyEventsComponent extends StreamlitComponentBase {
<Plot
data={plot_obj.data}
layout={plot_obj.layout}
config={plot_obj.config}
config={config}
frames={plot_obj.frames}
onClick={click_event ? this.plotlyEventHandler : function(){}}
onSelected={select_event ? this.plotlyEventHandler : function(){}}
Expand Down