How to use value using Streamlit.setComponentValue in streamlit.components.v1.html

Summary

I would like to get some value inside streamlit.components.v1.html and chatgpt recomend use Streamlit.setComponentValue but It maybe cannot use Streamlit.setComponentValue

for example code

Code snippet:

import streamlit as st
from streamlit.components.v1 import html

# Define the component's code
component_code = """
<div>
  <button id="my-button">Click me</button>
  <script>
    const button = document.getElementById('my-button');
    button.addEventListener('click', () => {
      // Send the value to the Streamlit app
      const value = 'Hello from the component';
      Streamlit.setComponentValue(value);
    });
  </script>
</div>
"""

# Render the component and get the value sent back
component_value = html(component_code)

# Display the value returned from the component
st.write("Value returned from the component:", component_value)

If applicable, please provide the steps we should take to reproduce the error or specified behavior.

Hi @Varintorn_Sithisint

Hereโ€™s a relevant forum post to getting a value from HTML:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.