awacke1 commited on
Commit
4658994
·
verified ·
1 Parent(s): 3f75756

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -54
app.py CHANGED
@@ -1,61 +1,37 @@
1
  import streamlit as st
2
- from streamlit.components.v1 import html
3
- import time
4
 
5
  def main():
6
- st.title("HTML to Streamlit Sync Demo")
7
 
8
- # Create a session state variable for the text
9
- if 'text_value' not in st.session_state:
10
- st.session_state.text_value = "Initial text..."
11
-
12
- # HTML component with a textarea
13
- html_code = """
14
- <textarea id="html-textarea" style="width: 100%; height: 150px; padding: 10px; margin: 10px 0;">
15
- This is text in the HTML textarea.
16
- Try editing this text!
17
- </textarea>
18
-
19
- <script>
20
- // Function to get textarea content
21
- function getTextareaContent() {
22
- let content = document.getElementById('html-textarea').value;
23
- // Send content to Streamlit
24
- window.parent.postMessage({
25
- type: 'streamlit:setComponentValue',
26
- value: content
27
- }, '*');
28
- }
29
-
30
- // Set up timer to check for changes
31
- setInterval(getTextareaContent, 1000); // Check every second
32
- </script>
33
- """
34
-
35
- # Column layout for side-by-side comparison
36
- col1, col2 = st.columns(2)
37
-
38
- with col1:
39
- st.subheader("HTML Textarea")
40
- # Render the HTML component
41
- html(html_code, height=200)
42
-
43
- with col2:
44
- st.subheader("Streamlit Textarea")
45
- # Streamlit textarea that shows the synced content
46
- synced_text = st.text_area(
47
- "Synced content (updates every second):",
48
- value=st.session_state.text_value,
49
- height=150,
50
- key="synced_textarea"
51
- )
52
-
53
- # Show the current value for debugging
54
- st.subheader("Current Value in Session State:")
55
- st.code(st.session_state.text_value)
56
-
57
- # Add a note about the sync behavior
58
- st.info("The content from the HTML textarea will sync to the Streamlit textarea every second. Try typing in the HTML textarea and watch the Streamlit textarea update!")
59
 
60
  if __name__ == "__main__":
61
  main()
 
1
  import streamlit as st
2
+ import urllib.parse
 
3
 
4
  def main():
5
+ st.title("Text Copy Demo")
6
 
7
+ # Create a text input
8
+ text_to_copy = st.text_input("Enter text to copy:", "Hello, World!")
9
+
10
+ # Encode the text for URL
11
+ encoded_text = urllib.parse.quote(text_to_copy)
12
+
13
+ # You'll need to replace this with your actual hosted HTML file URL
14
+ hosted_html_file = "https://your-domain.com/copy.html"
15
+ iframe_url = f"{hosted_html_file}?copy={encoded_text}"
16
+
17
+ # Create the iframe with some styling
18
+ st.markdown(
19
+ f"""
20
+ <iframe
21
+ src="{iframe_url}"
22
+ style="border: none; width: 60px; height: 45px; overflow: hidden;"
23
+ ></iframe>
24
+ """,
25
+ unsafe_allow_html=True
26
+ )
27
+
28
+ # Add some instructions
29
+ st.markdown("""
30
+ ### Instructions:
31
+ 1. Enter your text in the input field above
32
+ 2. Click the clipboard button to copy the text
33
+ 3. The button will show a checkmark when the text is copied
34
+ """)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
  if __name__ == "__main__":
37
  main()