Giter VIP home page Giter VIP logo

Comments (19)

treuille avatar treuille commented on May 14, 2024 1

Ok. This is very valuable. Thank you!

from awesome-streamlit.

treuille avatar treuille commented on May 14, 2024 1

from awesome-streamlit.

MarcSkovMadsen avatar MarcSkovMadsen commented on May 14, 2024 1

I will close this as I've found a work to enable hotreloading on all files in my end.

In the future you can referer to the Streamlit Github to follow the development.

from awesome-streamlit.

MarcSkovMadsen avatar MarcSkovMadsen commented on May 14, 2024

Please note I've refactored the project a lot so please so if you try to do the steps below please pull master first :-)


As far as I can see modules with st.something commands are not being reloaded automatically. As an example lets play around with the home.py file.

image

image

image

Then I change home.py

image

and click rerun

image

As you see nothing happens. I can also navigate to other pages and back and nothing happens. I can also click rerun again and nothing happens.

If I close the server and start all over and enable reload

image

image

image

and change

image

then at first nothing happens. But if i navigate to another page like the Vision page and back it's updated.

image

It's the same if I click the rerun once more instead of navigating to another page and back.

So In conclusion I cannot get automatic updates. But I can get semi-automatic updates if I navigate to another page and back.

Unfortunately I cannot run Streamlit on individual pages because I import relative to the root folder of the project but streamlit starts the app in the folder of the file. Thus I will get import errors :-)

image

image

The home.py file

"""Home page shown when the user enters the application"""
import streamlit as st
import streamlit_extensions as st_extensions

imports streamlit_extensions from the root folder of the project from which I start the project.

The workaround for now is putting the home.py file in the root folder while developing it.

from awesome-streamlit.

MarcSkovMadsen avatar MarcSkovMadsen commented on May 14, 2024

And I also think Streamlit should have a way of fixing it.

Maybe it's my app structure that should be changed or maybe the assumption of Streamlit has been that all files are in the same folder?

from awesome-streamlit.

treuille avatar treuille commented on May 14, 2024

As far as I can tell, Streamit should properly reload modules in this case. Ok for me to submit a Streamlit bug report referencing this issue?

from awesome-streamlit.

MarcSkovMadsen avatar MarcSkovMadsen commented on May 14, 2024

from awesome-streamlit.

treuille avatar treuille commented on May 14, 2024

Ok. Just added the bug. It would be very helpful if you could add some information as specified. Thanks! ❤️

from awesome-streamlit.

MarcSkovMadsen avatar MarcSkovMadsen commented on May 14, 2024

Hi @treuille

One of the problems is that the modules i'm reloading are actually not in sys.modules! I don't understand why but if I change to code to

image

and run

streamlit run app.py

It's showing the home.py, file.

If I change the spreadsheet.py code, go to the gallery.py page and select the spreadsheet.py subpage then I see

image

so src.pages.gallery.spreadsheet is not in sys.modules before the reload! But I can see it is after!

So I believe a hack for me now is to run the reload in the exception handling as well.

from awesome-streamlit.

MarcSkovMadsen avatar MarcSkovMadsen commented on May 14, 2024

I've tried adding

image

But that does not change anything. I still have to reload twice or reload and interact with widget before the change takes effect.

from awesome-streamlit.

MarcSkovMadsen avatar MarcSkovMadsen commented on May 14, 2024

In the src/pages/gallery/index.py file I tried changing

image

to

image

But that does not change anything either.

from awesome-streamlit.

MarcSkovMadsen avatar MarcSkovMadsen commented on May 14, 2024

I've tried importing spacyio, spreadsheet in the app.py file that is run by Streamlit

image

But that does not change anything either. Still need to reload twice.

from awesome-streamlit.

MarcSkovMadsen avatar MarcSkovMadsen commented on May 14, 2024

But (Hurra!!!!). when I added spacyio and spreadsheet as below

image

I get automatic reload!!!!!

Don't ask me why :-)

FYI @treuille

from awesome-streamlit.

MarcSkovMadsen avatar MarcSkovMadsen commented on May 14, 2024

And now if I change the imports in app.py to absolute imports

image

I can remove the importlib.reload

and have automatic updates !!!!

image

This solves my problem. But I guess @treuille that you could have other users experiencing the same problem and have to help them. Maybe there is something to understand and fix wrt. the way you use sys.modules?

Thanks for the help.

from awesome-streamlit.

MarcSkovMadsen avatar MarcSkovMadsen commented on May 14, 2024

I tried removing imports of spacyio and spreadsheet from app.py and

image

and add them in the src/pages/gallery/index.py file.

image

But then autoreload of spreadsheet.py stopped

I tried some more things to see if I could avoid making unused imports in app.py or anywhere. But I could not.

Bottom line: all imports must be done in app.py and in a specific way for autoreload to work.

from awesome-streamlit.

MarcSkovMadsen avatar MarcSkovMadsen commented on May 14, 2024

One more fun fact is that autoreload works for src.shared.components.st_awesome but not for st_extensions!

image

But if I move the st_extensions file and change to

image

The I get autoreload as well.

from awesome-streamlit.

MarcSkovMadsen avatar MarcSkovMadsen commented on May 14, 2024

Argghhh :-)

My understanding now is that

  1. It works mostly if you use the the full path like
import x.y.z

and not

import x.y.z as z
from x.y import z

And definately you should use the same import convention across all files.

  1. st_extensions and st_awesome do not get autoreload if I put them in the root folder but they get autoreload if I put them in a subfolder. For example if they are in the src folder and I use
import src.st_extensions
import src.st_awesome
  1. I cannot get autoreload to work for src.pages.gallery.spacyio and src.pages.gallery.spreadsheet unless I add the importlib.reload

image

image

If I stick to the above imports then I get autoreload for everything and no exceptions in the write_page function

image

Phew :-)

from awesome-streamlit.

treuille avatar treuille commented on May 14, 2024

Hi @MarcSkovMadsen : I have factored the bug report into two different issues: 358 and 366.

Do those two isssues cover everything you've observed, or is there more we need to cover? Thanks!

from awesome-streamlit.

MarcSkovMadsen avatar MarcSkovMadsen commented on May 14, 2024

I have a feeling you don't cover everything. Each possible way of importing should be covered.

I've created an example file structure here.

If I could get hot reloading in all files I think that would cover most peoples use cases.

I guess I'm the first one trying to develop an app in multiple pages/ multiple files so getting a good practice for that and improving Streamlit to fit that use case is important.

streamlit run a.py

a.py

import streamlit as st
import st_extensions  # Hot reloading works in st_extensions.py file
import bf.b  # Hot reloading works in b.py file
from bf2 import b2  # Hot reload does not work in b2.py file
from bf3 import b3 as b3_new_name  # Hot reload does not work in b3.py file
import bf4.b4 as b4_new_name  # Hot reload works in b4.py file

# c hot reloading does not work in bf/cf/c.py file through file bf/b.py
# d hot reloading does not work in bf/cf/df/d.py file through file bf/cf/c.py

st.write("this is a")

bf.b.write()
b2.write()
b3_new_name.write()
b4_new_name.write()
st_extensions.write("awesome")

from awesome-streamlit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.