Embeding streamlit into Iframe with parameters

Hi!

Is there a way to embed streamlit app, lets take for example some simple app, but to send parameters to there, for example send x & y to there when the app is in iframe?

import streamlit as st
x = number_input(‘x’)
y = number_input(‘y’)
st.write(x+y)

Never mind, resolved.

For whom it may concern:

url with params :

http://localhost:8501/?x=10&y=20

page.html:

<!DOCTYPE html>

<html>

<body>

<h1>Iframe streamlit Demo</h1>

<p><strong>Url: </strong>http://localhost:8501/?x=10&y=20</p>

<center>

<iframe src="http://localhost:8501/?x=10&y=20" width="600" height="600">

  <p>Your browser does not support iframes.</p>

</iframe>

</center>

</body>

</html>

app.py:

import streamlit as st

def get_param(param_name):
    query_params = st.experimental_get_query_params()
    try:
        return query_params[param_name][0]
    except:
        st.write('Parameters is missing')
        return False

def get_params(params_names_list):
    query_params = st.experimental_get_query_params()
    responses = []
    for parameter in params_names_list:
        try:
            responses.append(query_params[parameter][0])
        except Exception as e:
            responses.append(None)
    return responses

x = st.number_input('X Parameter',value = float(get_param('x')))

y = st.number_input('Y Parameter',value = float(get_param('y')))

st.write(x+y)

1 Like