Introducing multipage apps! 📄

Hi everyone!

Thanks for the nice update, really cool work which will be very nice in developing larger apps!

I have had one thought that might be interesting to think about now that the multi-page apps are possible though. In my opinion it would be good to think about the way we have to import and / or define functions, in combination with caching.

In a lot of my cases (I’m building interactive image-analysis apps), I’m using similar functions in all my ‘pages’ (slightly different image analysis tools). For example, I’m using an intensity correction function in all my apps, lets call it modify_intensities() for this example. In order to speed things up, I like to use st.experimental_memo() on this function.

Previously, all of the different ‘pages’ were added to the same ‘main’ file, which meant all ‘pages’ could access my custum function modify_intensities(), which can easily then be used withst.experimental_memo().

If I would choose to split up my different applications into different pages with the new update, I would have to define modify_intensities() in all these pages, and add st.experimental_memo() on all these pages as well. This is fine on first sight, but not easy to maintain when I find some way to improve my function. Then I would have to go over all my page-files and change all these functions manually. Personally I’m fine with doing this for now, since the scale of my projects is not extremely large at the moment. However, since the apps I’m building are ever expanding, I think I can predict that these apps will become more difficult to maintain up-to-date in the future.

What I think would be ideal, is the use of a functions.py file. I got something working that is (kind of) solving this issue, but it is not the most elegant in my opinion.
Lets say I have a functions file called “custom_functions.py” next to my main.py script. I can then use from custom_functions import * or from custom_functions import modify_intensities to easily import the functions I want to all pages, while I only need to maintain one file to update all pages at once.
Problem here is the caching functionality. If I would like to (always, in all pages) use st.experimental_memo() on modify_intensities(), I would have to do this in every page-file:

from custom-functions import *

@st.experimental_memo()
def cached_modify_intensities(x):
    return modify_intensities(x)

It is the cleanest and easiest solution that I could think of right now, but maybe there is a better way that I don’t know of. Do you think this should be improved, or is this just a detail that I’m worried about?

Ideally I think it would be great if (somehow) we could already define the caching in the custom_functions.py file, but that will be difficult I think.

Again, thanks for all the great work, I’m really happy with the functionality of streamlit, and also with the pace that the improvements are being made!

1 Like