ChrisDelClea / streamlit-agraph

A Streamlit Graph Vis
MIT License
387 stars 52 forks source link

Pass Click Values to Python #12

Closed ryanallen82 closed 2 years ago

ryanallen82 commented 3 years ago

I'm not sure if this is currently possible, but it would be great if there was a way to pass the click value (i.e. Clicked on node {value}) back to Streamlit/Python to save as a variable or filter a dataframe. For example if I clicked on Node 1 it would be able to pass Node 1 back so I could use it to filter a dateframe to only show rows containing Node 1.

ChrisDelClea commented 3 years ago

Hey @ryanallen82 ,

good idea, i'd like to have it too. I will think about it and let know if it is possible!

zjorgensenbits commented 3 years ago

agree, would be super useful!

zjorgensenbits commented 3 years ago

I figured out how to do this. Just edit streamlit_agraph/frontend/src//AgraphComponent.tsx and add Streamlit.setComponentValue(nodeId); to the click handlers, in place, or in addition to, the alert window. Then, in your Python code, the agraph widget's value will evaluate to the clicked ID. Make sure you rebuild and reinstall the module after you make the modification:

cd streamlit_agraph/frontend
npm install
npm run build
cd ../..
pip install -U -e streamlit-agraph 
ryanallen82 commented 3 years ago

Sweet! Good work and thank you!

On Tue, Apr 6, 2021, 4:23 PM Zach Jorgensen @.***> wrote:

I figured out how to do this. Just edit streamlit_agraph/frontend/src//AgraphComponent.tsx and add Streamlit.setComponentValue(nodeId); to the click handlers, in place, or in addition to, the alert window. Then, in your Python code, the agraph widget's value will evaluate to the clicked ID. Make sure you rebuild and reinstall the module after you make the modification:

cd streamlit_agraph/frontend npm install npm run build cd ../.. pip install -U -e streamlit-agraph

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ChrisChross/streamlit-agraph/issues/12#issuecomment-814448541, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAE7NOGW3R2HS3VAQWMQV43THN3UHANCNFSM4XRBEGRQ .

ChrisDelClea commented 2 years ago

Tanks for the pull request @zjorgensenbits. Could you please provide an example how to use that in python code?