I recently deployed this app on share.streamlit. th eapp allows the user to edit scenarios and saves every change to a json file. the user can also create new scenarios. this works well locally, but on share.streamlit.io, I get the error. PermissionError: [Errno 13] Permission denied: ‘scenarios.json’. This happens with this code:
with open('scenarios.json', 'wt') as myfile:
json.dump(self.scenarios, myfile)
where scenarios is a dictionary holding all scenarios (to start with jst the default one).
The full code can be found on github.
Am I not allowed to save changes on share.streamlit? Is there an alternative to persist user input for future sessions? Thanks in advance on any insight on my problem.
hi @franciscoed, thank you for your suggestion, but moving the file to a folder did not help, still getting the "PermissionError: [Errno 13] Permission denied: ‘./tmp/scenarios.json’ " error. Eventually, I will add the username to the settings dictionary, so all users have their own setting, but first I need the basics to work. Also, I wonder: how do I prevent each deployment to overwrite my most recent settings generated during a session?
I would like to know, if it is generally not possible to write files on streamlit.sharing. I made the simple example below which works locally but not when deployed to streamlit sharing (again, error: PermissionError: [Errno 13] Permission denied: ‘demofile.txt’). What would be the alternative if I need the users to generate new scenarios and keep the saved scenarios persistent?
import streamlit as st
def main():
st.write('testing writing a file')
f = open("demofile.txt", "w")
f.write("Now the file has some content!")
f.close()
f = open("demofile.txt", "r")
st.write(f.read())
if __name__ == '__main__':
main()
import streamlit as st
def main():
st.write('testing writing a file')
f = open("/tmp/demofile.txt", "w")
f.write("Now the file has some content!")
f.close()
f = open("/tmp/demofile.txt", "r")
st.write(f.read())
if __name__ == '__main__':
main()
thanks for your answer @franciscoed. I tried this, but it does not seem work in the streamlit-sharing environment either. still getting the permission error, while the same code works locally.
Yes it worked! However now it does not work locally anymore, since I am working on windows and /tmp produces a file not found error. However the issue is now clear and I simply used os.path.join to build the filename which now works on linux and windows. I was searching the error in the wrong direction. Thanks again!
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.