New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem with session_id #13
Comments
some code would be helpful, as the session state management in Hydralit isn't exactly the same as Streamlit and the "answers" on the forum aren't specific to Hydralit. Hydralit needs to know your custom session parameters ahead of time, as you might want to share them across apps, so the approach is to tell Hydralit in the constructor about your session state parameters, then you get or set their values from the parent or child apps using some simpler methods than the "hacks" they talk about in the forums. For example, if you want to add two parameters called "session_id" and "my_special_value" to the app and have it available across all the child apps, if you are using the decorator method to add apps, you can get/set the values as per the example below. ` #custom user session parameters to share across apps app = hy.HydraApp(title='Simple Multi-Page App',navbar_animation=True, session_params=user_s_params) @app.addapp(is_home=True) @app.addapp() @app.addapp(title='The Best', icon="🥰") #Run the whole lot, we get navbar, state management and app isolation, all with this tiny amount of work. #print all the user defined session state parameters and their values you can get the value of any user parameter by calling app.get_user_session_params(), this returns a dict with the key/values of your parameters. You can set the value from within a child app or the parent by directly assigning a value, app.session_state.session_id=51 If you are using the class method to create a child app, it is still recommended you create and provide a default value for the parameters at the start in the constructor for the HydraApp, the only difference is within the child you can get/set the user parameters you defined like this, If you try to assign a value to a session state parameter within a child app that doesn't exist, it will be automatically created for you, for example You can access this from any other child apps once it is create, like this, self.session_state.crazy_value, if it doesn't exist, you will get the much more informative error, If you simple and directly assign a value to a new parameter, that will create it automatically for you from within the both the parent and child apps. The catch is you haven't specially told the parent about this parameter, so when you call app.get_user_session_params(), it won't appear. Doesn't mean it isn't there, you simply have defined it at the start. Hydralit was built to allow flexibility, but encourage best practise. |
Hi!, i have use the exact same code that you show and it stills gives me the error AttributeError: 'NoneType' object has no attribute 'session_id'. sorry, i'm not an experct in python, and i'm trying to use Hydralit for a project. I really appreciate your time to help me. |
This is the raw error
|
Are you running your script borrar.py with this command: This won't work, Streamlit and Hydralit have to be run using the Streamlit run command, like this in your case. streamlit run borrar.py Can you please confirm what version of Streamlit and Hydralit you are running? If you could also share some code, as the only reason for an error with the session state like is for some reason your environment isn't able to even create a Streamlit session object, very odd. |
Yes, this is the exact code. The code from 'borrar.py' is the same: def main():
if name == "main": When i run it in sublime text gives the error When i run it in the terminal with streamlit run main.py it runs the app and open it in the browser but gives the next error:
It shows the title 'Club IQ', but it does not show anything more, just the error. The error also appears in the terminal. |
ok, for starters i can see alot wrong with your code, instead of me completely rewriting your code so it works, i suggest you have another look at the example code in the read me on the home page, https://github.com/TangleSpace/hydralit There is also an extensive example application located here, https://github.com/TangleSpace/hydralit-example Your Python code isn't correct, don't worry about Streamlit or Hydralit, for example, when you run a file called "borray.py", you don't use the commend main is the function, not the file name. Also, this line is completely incorrect this is basic Python, it should be, It also appears whatever Club_IQ and Scout_IQ are, these need to be Python classes that inherit from HydraHeadApp like the sample on converting or wrapping code in the read me, for example like this.
or you can just write python functions and use the decorator method to add them as apps, again two examples are in the read me https://github.com/TangleSpace/hydralit for example, don't touch anything about this code, just put it in a file named example.py and run it with the command
|
Hi!, i'm trying to make a multi page with hydralit and i keep gettin this error:
AttributeError: 'NoneType' object has no attribute 'session_id'
I found a answer to this problem in the streamlit webb, wich was:
`
def _get_state(hash_funcs=None):
try:
session = _get_session()
except (AttributeError, NameError):
session = sys
`
But when i dont' really know how to do it, when i call this function in my code gives me another error:
NameError: name '_get_session' is not defined
The text was updated successfully, but these errors were encountered: