Created
November 13, 2019 21:00
-
-
Save monchier/b3c200a002f8030db07fa72f8827f10f to your computer and use it in GitHub Desktop.
Patch to Streamlit Server.py to allow for an extra endpoint to download a static file
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
diff --git a/lib/streamlit/server/Server.py b/lib/streamlit/server/Server.py | |
index c292a48e..199128a9 100644 | |
--- a/lib/streamlit/server/Server.py | |
+++ b/lib/streamlit/server/Server.py | |
@@ -153,6 +153,16 @@ def start_listening(app): | |
) | |
+class MyFileHandler(tornado.web.StaticFileHandler): | |
+ def initialize(self, path): | |
+ self.dirname, self.filename = os.path.split(path) | |
+ super(MyFileHandler, self).initialize(self.dirname) | |
+ | |
+ def get(self, path=None, include_body=True): | |
+ # Ignore 'path'. | |
+ super(MyFileHandler, self).get(self.filename, include_body) | |
+ | |
+ | |
class Server(object): | |
_singleton = None | |
@@ -260,6 +270,7 @@ class Server(object): | |
routes.extend( | |
[ | |
+ (r"^/text/?$", MyFileHandler, {"path": os.path.join(os.getcwd(), "custom_static", "text")}), | |
( | |
make_url_path_regex(base, "(.*)"), | |
StaticFileHandler, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment