awacke1 commited on
Commit
03c6044
1 Parent(s): 8b258ba

Create index.html

Browse files
Files changed (1) hide show
  1. mycomponent/index.html +66 -0
mycomponent/index.html ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <html>
2
+ <body>
3
+ <!-- Set up your HTML here -->
4
+ <input id="myinput" value="" />
5
+
6
+ <script>
7
+ // ----------------------------------------------------
8
+ // Just copy/paste these functions as-is:
9
+
10
+ function sendMessageToStreamlitClient(type, data) {
11
+ var outData = Object.assign({
12
+ isStreamlitMessage: true,
13
+ type: type,
14
+ }, data);
15
+ window.parent.postMessage(outData, "*");
16
+ }
17
+
18
+ function init() {
19
+ sendMessageToStreamlitClient("streamlit:componentReady", {apiVersion: 1});
20
+ }
21
+
22
+ function setFrameHeight(height) {
23
+ sendMessageToStreamlitClient("streamlit:setFrameHeight", {height: height});
24
+ }
25
+
26
+ // The `data` argument can be any JSON-serializable value.
27
+ function sendDataToPython(data) {
28
+ sendMessageToStreamlitClient("streamlit:setComponentValue", data);
29
+ }
30
+
31
+ // ----------------------------------------------------
32
+ // Now modify this part of the code to fit your needs:
33
+
34
+ var myInput = document.getElementById("myinput");
35
+
36
+ // data is any JSON-serializable value you sent from Python,
37
+ // and it's already deserialized for you.
38
+ function onDataFromPython(event) {
39
+ if (event.data.type !== "streamlit:render") return;
40
+ myInput.value = event.data.args.my_input_value; // Access values sent from Python here!
41
+ }
42
+
43
+ myInput.addEventListener("change", function() {
44
+ sendDataToPython({
45
+ value: myInput.value,
46
+ dataType: "json",
47
+ });
48
+ })
49
+
50
+ // Hook things up!
51
+ window.addEventListener("message", onDataFromPython);
52
+ init();
53
+
54
+ // Hack to autoset the iframe height.
55
+ window.addEventListener("load", function() {
56
+ window.setTimeout(function() {
57
+ setFrameHeight(document.documentElement.clientHeight)
58
+ }, 0);
59
+ });
60
+
61
+ // Optionally, if the automatic height computation fails you, give this component a height manually
62
+ // by commenting out below:
63
+ //setFrameHeight(200);
64
+ </script>
65
+ </body>
66
+ </html>