Hi @thiago, Thanks for this code snippet
I just need the screen width and height to use in my application. This functionality seems to be helping my case.
I changed the code piece in index.html.
// data is any JSON-serializable value you sent from Python,
// and it's already deserialized for you.
function onDataFromPython(event) {
var width = window.screen.width
var space = " "
var height = window.screen.height
if (event.data.type !== "streamlit:render") return;
// myInput.value = event.data.args.my_input_value; // Access values sent from Python here!
myInput.value = [width, height]
}
and I am getting this output. I dont want the message to be displayed in text input rather need width and height as a variable in backend python. the value is always None. What should I do for my request. Please guide
@Murugan_Yuvaraaj_M_P Are you calling sendDataToPython in your script anywhere? That’s what you’ll need to call in order to send the data back to your python script.
If you’re interested, I created a cookiecutter template for creating a component that uses a slightly modified version of Thiago’s snippet and wrote a blog post showing how to use it How to build your own Streamlit component
In addition to @thiago’s and @blackary’s articles I wrote one which starts from the very basics and progresses towards a full blown React / Next.js component design. You can read up to the end of section “Component Zero”.
hey @thiago, this is really cool, thanks a lot for sharing.
I am trying to have a clickable list of items so wanted to slightly alter your example with the click event and it looks like it somehow triggers twice so the variable is reset. Any idea how to prevent that?
The same is happening to the click detector lib, and it looks like more people have experienced this. Duplication when clicking · Issue #9 · vivien000/st-click-detector · GitHub
this is all i added to your code, and its still working fine with the change event.
ok, my example is wrong, i had 2 eventlisteners. the issue with double load is when I click on a table generated by pandas - so i guess there are some more events in play.
@thiago
Thanks you so much for made this code snipset.
I’m trying to custom my own html component to paste image from clipboard to streamlit, I dont know how to modify js functions in your index.html component to get data from clipboard. Can you give me an advice for it ? Thank you.
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.