Last active
May 18, 2023 17:09
-
-
Save asehmi/45eaa4482a424872c281b8270bfecb9a to your computer and use it in GitHub Desktop.
How to cleanly embed a Streamlit app in a web page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
This is a sample HTML file that you can use to embed your Streamlit app in an iframe. | |
The Streamlit app is embedded cleanly and is almost indistinguishable from a native app. | |
Use it as a template and customize it to your needs. | |
NOTE: It's convenient to start your Streamlit app in headless mode, for example | |
$ streamlit run --server.port=8005 --server.headless=true app.py | |
--> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>My App</title> | |
<style> | |
html, body { | |
height: 100%; | |
} | |
.scroll { | |
background-color: #FFFFFF; | |
width: 100%; | |
border: 0px; | |
overflow-y: hidden; /* Remove the ability to scroll */ | |
} | |
/* Hide scrollbar for Chrome, Safari and Opera */ | |
.scroll::-webkit-scrollbar { | |
display: none; | |
} | |
/* Hide scrollbar for IE, Edge and Firefox */ | |
.scroll { | |
-ms-overflow-style: none; /* IE and Edge */ | |
scrollbar-width: none; /* Firefox */ | |
} | |
</style> | |
</head> | |
<body class="scroll"> | |
<div id="st_embedded"></div> | |
</body> | |
<script> | |
/* CHANGE THIS TO YOUR APP URL */ | |
let ST_APP_URL = "http://localhost:8005"; | |
let src = ST_APP_URL + "/?embedded=true"; | |
let width = "100%"; | |
let height = screen.height; | |
let iframe = '<iframe src="' + src + '" width="' + width + '" height="' + height + '" style="border:none;"></iframe>'; | |
console.log(iframe); | |
document.getElementById("st_embedded").innerHTML = iframe; | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment