I am currently getting the follow error when trying to run this code:
'SessionState' object has no attribute 'input'
I am currently getting the follow error when trying to run this code:
'SessionState' object has no attribute 'input'
Hello @Codeguyross,
Could you share your source code? It’d be easier to identify the problem.
My class has an underscore before SessionState
. Maybe you tried to use this class along with Thiago’s ?
Hi @okld I am referring to this example to get better understanding of Session State Management
Hello @Gaurav_Gupta,
So you seem to have the same kind of error as @Codeguyross. In both cases, the exception is related to a SessionState
object which I don’t use. In my code there is an underscore prepended: _SessionState
.
Could you share your source code? I need more info to identify the issue.
Hi @okld
Hello @Gaurav_Gupta,
You have removed all the methods of my SessionState class in your code, no doubt it doesn’t function properly now ^^. The method which allows you to set new items in your class is __setattr__()
. And you also need to access them by implementing __getattr__()
. Include all the function I implemented (not only the 2 I mentioned), and it should work better.
And also, in your example you need to call state.sync()
at the very end of your app to avoid rollback issues with your slider.
Hi @okld
I haven’t used that beacuse I can’t see that we are calling that methods anywhere.
If possible can you explain me briefly.
Methods surrounded by two underscores are called magic methods. Like the constructor __init__()
, they’re not meant to be called explicitly in your code, but are used when you interact with an instance of your class in some specific ways.
Let’s say you have initialized a new state object with state = SessionState()
.
To summarize briefly what each method does:
__call__(self, arguments)
: called when you do state(arguments)
, you use state as if it was a function.__getitem__(self, item)
: called when you do state["My item"]
. In the function, item == "My item"
__getattr__(self, item)
: called when you do state.my_item
. In the function, item == "my_item"
__setitem__(self, item, value)
: called when you do state["My item"] = "my value"
. In the function, value == "my value"
__setattr__(self, item, value)
: called when you do state.my_item = "my value"
. In the function, value == "my value"
There are more magic methods that I don’t use for other specific usages. You have some tutorials/blogs presenting and explaining more of them in details if you’re interested:
Hi @okld
Thanks for your kind. Now its done its working and maintaining the state too.
Hi @okld
After updating to the latest Streamlit version, I’ve came across an error
ModuleNotFoundError: No module named 'streamlit.ReportThread'
Have you implemented anything new to overcome this? Thanks.
Hello @vnguyendc,
I didn’t had time to check all the recent Streamlit changes, but with release 0.65 there was some code refactoring that broke session state implementations. I’ll work on it asap!
Alright, I’ve made a quick (untested ) fix. I’ve walked through the new code, and there was no major change in the parts I use. Some python files were renamed, and updating the imports should be enough.
Thanks. Yes it works on v0.65.
Off-topic:
Is there a way to persist the session state across refreshes?
Maybe something like getting the device fingerprint should do right, instead of session id?
Is there a way for that? Or can it be added?
If memory serves me correctly, there’s another implementation of state with a GlobalState
that is maintained between refreshes.
Great, thanks! That worked.
But it seems to be global for anyone accessing the page from anywhere.
This would be a good solution for that right?
It’s an interesting proposition…could you take this in another post on the forum so we don’t hijack this one too much ?
I still get this error 'ModuleNotFoundError: No module named ‘streamlit.ReportThread’ after installing 0.65.0. Do i need to explicitly change anything in my code?
Hi @okld
Thanks for your sharing.
Can you share how can set up Session State for multi users working. As I use Session State of @thiago but session merge btw each users frequently
In my app, That’s embed in our ERP system, where one user click to Streamlit App, will have one auth_token in url para it’s user_id. But when other users come to same time, it’s will go to earler user session.
Do you have some advise for me?
I have been getting it aswell. Not sure how onerous it would be for your code, but you could always write the data using pickle and read it again when you need it at a later stage. Its how I over came this issue…not the most elegant solution but it worked…
Hmm, this is weird. Merging is not supposed to happen and may be related to another problem. Could you share some code reproducing the issue you’re encountering?
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.
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.
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.
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.