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
2 changes: 2 additions & 0 deletions src/streamlit_plotly_events/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def plotly_events(
hover_event=False,
override_height=450,
override_width="100%",
return_fields=False,
key=None,
):
"""Create a new instance of "plotly_events".
Expand Down Expand Up @@ -102,6 +103,7 @@ def plotly_events(
click_event=click_event,
select_event=select_event,
hover_event=hover_event,
return_fields=return_fields,
default="[]", # Default return empty JSON list
)

Expand Down
3 changes: 2 additions & 1 deletion src/streamlit_plotly_events/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
"@types/react": "^16.9.0",
"@types/react-dom": "^16.9.0",
"plotly.js": "^1.58.2",
"pretty-format": "^28.1.1",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-plotly.js": "^2.4.0",
"react-scripts": "3.4.1",
"streamlit-component-lib": "^1.2.0",
"typescript": "~3.7.2"
"typescript": "~3.8.0"
},
"devDependencies": {
"@types/plotly.js": "^1.50.16",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class StreamlitPlotlyEventsComponent extends StreamlitComponentBase {
const click_event = this.props.args["click_event"];
const select_event = this.props.args["select_event"];
const hover_event = this.props.args["hover_event"];


Streamlit.setFrameHeight(override_height);
return (
Expand All @@ -36,16 +37,22 @@ class StreamlitPlotlyEventsComponent extends StreamlitComponentBase {

/** Click handler for plot. */
private plotlyEventHandler = (data: any) => {
const return_fields = this.props.args["return_fields"];

// Build array of points to return
var clickedPoints: Array<any> = [];
data.points.forEach(function (arrayItem: any) {
clickedPoints.push({
x: arrayItem.x,
y: arrayItem.y,
curveNumber: arrayItem.curveNumber,
pointNumber: arrayItem.pointNumber,
pointIndex: arrayItem.pointIndex
})
let clickedPoint: any = {};
clickedPoint.x = arrayItem.x;
clickedPoint.y = arrayItem.y;
clickedPoint.pointNumber = arrayItem.pointNumber;
clickedPoint.pointIndex = arrayItem.pointIndex;
clickedPoint.curveNumber = arrayItem.curveNumber;
if (return_fields){
clickedPoint.customdata = arrayItem.customdata;
}

clickedPoints.push(clickedPoint);
});

// Return array as JSON to Streamlit
Expand Down