File write error

Hi! I am quite new to streamlit and I am getting permission error while editing the streamlit theme file and a pickle file where I have some news data stored.

check my app from here: https://share.streamlit.io/sameerjain901/coronavisualizer/visualizer.py
I have a selectbox to select from different themes but it is not working on streamlit-sharing as I do not have permission to edit the toml file.

It works on local system:

Hi @SameerJain901, welcome to the Streamlit community!! :wave: :partying_face:

I’m sorry that you’re running into permission errors on Streamlit sharing. Here’s how you can fix the errors associated with updating your config.toml file and dumping card_data.pkl to disk.

Pickle:

  1. On sharing, all the scripts associated with your app live in the /app/ directory. Pickle can write to this directory

  2. Prepend /app/ to the path of your pickle files by editing line 262 and line 496 of visualizer.py to be

    # line 262
    pk.dump(card_data,open('/app/card_data_2.pkl','wb'))
    
    # line 496
    card_data=pk.load(open('/app/card_data_2.pkl','rb'))
    

Theming

  1. The error is caused by line 141

    os.remove('.streamlit/config.toml')
    
  2. Either remove line 141 or comment it out

  3. Uncomment lines 142 and 143 such that your update_theme() function looks like the following:

     def update_theme(primaryColor,backgroundColor,secondaryBackgroundColor,textColor,font):
         # Theme Base
         theme_data=['[theme]\n\n','primaryColor=\"%s\"\n'%(primaryColor),
         'backgroundColor=\"%s\"\n'%(backgroundColor),
         'secondaryBackgroundColor=\"%s\"\n'%(secondaryBackgroundColor),
         'textColor=\"%s\"\n'%(textColor),
         'font=\"%s\"\n'%(font)]
         theme_file=open('.streamlit/config.toml','w+')
         theme_file.writelines(theme_data)
    

Once you make the :point_up: above changes, and Reboot your app, both the errors should be resolved :grinning_face_with_smiling_eyes:

Happy Streamlit-ing! :balloon:
Snehan

Thanks @snehankekre. It is running smoothly. I did not notice that I was deleting the config file.

1 Like