Add file picker dropdown to sidebar?

Hello!

So I’m just getting back into ML, and wanted to know if there was a way to add a dropdown menu to the sidebar, where it will then load the *.py file you have chosen, and then render it like usual?

Thank you for a great app!

Hi @peterstorm, welcome to the Streamlit community!

In general, you can add “sidebar” to the function name to place things in a sidebar:

import streamlit as st
fp = st.sidebar.file_uploader("hello") 

But how would I then render the file?

And I feel like I would need to traverse the directory to look for files, and then list them in the dropdown.

But again, then how would I render that file?

Maybe I’m not understanding what you’re trying to do here. What files are you trying to provide to the user, and what does “render” mean in this context? What is contained in the .py files?

Well, the *.py file would just be a streamlit app, like a chapter in a book. So the dropdown would be like a table of contents, and you could choose what you wanted to read.

So i would have an app explaining neural networks for example, contained in nn.py and one for numpy in numpy.py, and then those files (with custom names preferebly) would be listed in the dropdown, and then “rendered” as you choose them.

Oh, actually like this, so I’ll just try and see how he did it I guess.

But it would be great if it was built in.

I see. We do something like that with our hello demo:

But you seem to have the demos imbedded in one file. Can it be done with multiple files? Again, want different *.py files, if possible.

I’m sure it’s possible, whether you write the separate files as functions or do conditional import or something. And though I wouldn’t recommend it, I suppose it’s possible to use the eval() function to do something like.

Finally, I suppose it would be possible to use a specific Streamlit instance to start other instances of Streamlit and then iframe them into the original instance, but that feels a bit too much of a hassle to me. Depends on how badly you want to do this I suppose.