This is my html code:
This is my streamlit code:
import streamlit as st
import streamlit.components.v1 as components
import json
Sample data
data = [
{“Name”: “John Doe”, “Age”: 30, “Occupation”: “Software Engineer”},
{“Name”: “Jane Smith”, “Age”: 25, “Occupation”: “Data Scientist”},
{“Name”: “Emily Davis”, “Age”: 35, “Occupation”: “Project Manager”},
]
Read HTML file content
def load_html(file_path, data):
with open(file_path, ‘r’) as file:
html_content = file.read()
data_json = json.dumps(data)
# Embed the data in the HTML content
html_content = html_content.replace(‘’, f’')
return html_content
st.title(“Custom Table Component Example”)
Path to the HTML file
html_file_path = ‘my_table_component/index.html’
Display the custom table component
html_content = load_html(html_file_path, data)
components.html(html_content, height=600, scrolling=True)
Simulate component value for demonstration purposes
component_value = {“selected_row”: {“Name”: “John Doe”, “Age”: 30, “Occupation”: “Software Engineer”}}
Check if component_value is set and display it
print(“Hello”)
st.write(st.session_state)
print(type(component_value))
st.write(json.loads(component_value))
if component_value:
st.write(“Received Data:”)
print(component_value, “inside if”)
# st.write(component_value)
st.write(“Hello World!”)