question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Enable `streamlit run` to serve a list of apps.

See original GitHub issue

Problem

You don’t just have one app file. But many. Right now streamlit will only serve one app.

Solution

Enable streamlit run without a file name to serve a folder of apps. Just like Voila does

image

Additional context

Consider whether this requires some configuration options in the configuration file

  • Serve subfolders as well?
  • Serve all python files or just some satisfying a filter like *app.py?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:20
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
isConiccommented, Nov 6, 2019

Questions:

  • Is this a feature for developers to navigate their projects?
  • Or is it for navigation of a set of tools once they’ve been written?

For users and tools: If I recall correctly, around 2016 airbnb open-sourced something called knowledge repos for organizing jupyter notebooks. My understanding is that it never took off, however it had some really nice UI features for navigating projects.

Here is an example of what the nb navigation gui looked like.

image

I’m throwing this sort of thinking in as an idea. I am bad at follow-through since I’m not well versed in web.

Heres a link to the knowledge repo: https://github.com/airbnb/knowledge-repo

3reactions
SimonBiggscommented, Oct 5, 2020

My thought with this would be to have an index.py app which runs at the root path, and then every other example.py test.py etc would run at http://hostname.com/example and http://hostname.com/test.

The idea is that the CLI would point to a directory, if that directory does not contain an index.py a template one would be created, and it would do a little bit of a sanity check to make sure that the built in names are not being overwritten (healthz, stream, etc):

https://github.com/streamlit/streamlit/blob/a20aba7fbc0380b8ed05664f33275d81435a2df7/lib/streamlit/server/Server.py#L296-L330

So CLI usage would be:

streamlit run path/to/a/directory

and the directory tree could look something like:

path/to/a/directory
 | index.py
 | example.py
 | boo.py
 | foo.py
 | etc.py

Importantly, if any of the scripts imports a shared function that is cached, this cache should be shared amongst them so that the server scales appropriately (without doubling up on caching).

An example index.py that could be created and placed within that directory if an index.py doesn’t exist already might look a bit like the following:

import pathlib

import streamlit as st


HERE = pathlib.Path(__file__).parent

base = st.config.get_option("server.baseUrlPath")

all_links = []

if len(base) != 0:
    base += '/'

for path in HERE.rglob('*.py'):
    relative_path = path.relative_to(HERE)
    suffix_removed = relative_path.with_suffix("")
    
    url = str(suffix_removed).replace('\\', '/')
    url = f'/{base}{url}'
    
    if suffix_removed.name == "index":
        url = '/'.join(url.split('/')[:-1])
        
    all_links.append(url)
        
markdown_urls = "\n\n".join([f"[{link}]({link})" for link in all_links])
markdown_urls

This index.py template could be further improved by also importing watchdog, and when the directory tree changes (such as a new python file added), then the following function could be run:

def rerun():
    raise st.ScriptRunner.RerunException(st.ScriptRequestQueue.RerunData(None))

Which would rerun the script, and update the URLs 😃.


[EDIT]

Turns out running the following within a watchdog thread doesn’t actually cause the parent thread to rerun, instead it just causes the watchdog thread to error out and stop:

def rerun():
    raise st.ScriptRunner.RerunException(st.ScriptRequestQueue.RerunData(None))

However the following PR addresses a means to rerun a streamlit session from within a watchdog thread:

https://github.com/streamlit/streamlit/pull/2060

[/EDIT]

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuration - Streamlit Docs
Streamlit provides four different ways to set configuration options. This list is in reverse order of precedence, i.e. command line flags take precedence ......
Read more >
Main concepts - Streamlit Docs
As soon as you run the script as shown above, a local Streamlit server will spin up and your app will open in...
Read more >
Add statefulness to apps - Streamlit Docs
We define access to a Streamlit app in a browser tab as a session. For each browser tab that connects to the Streamlit...
Read more >
Create an app - Streamlit Docs
Running a Streamlit app is no different than any other Python script. Whenever you need to view the app, you can use this...
Read more >
How to make "streamlit run example.py" run as a service or ...
Be sure to have Anaconda installed. Give that path to the root variable. Activate that conda environment. The path to your streamlit app...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found