Skip to content
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

[Bug] 0.89 Weird behavior in Multipage apps with query_params #3858

Closed
akshanshkmr opened this issue Sep 26, 2021 · 2 comments
Closed

[Bug] 0.89 Weird behavior in Multipage apps with query_params #3858

akshanshkmr opened this issue Sep 26, 2021 · 2 comments
Labels
status:needs-triage Has not been triaged by the Streamlit team type:bug Something isn't working

Comments

@akshanshkmr
Copy link

Summary

I noticed a weird behavior of query_params with the version 0.89
The query params keep resetting to the previous value, the user has to click twice to update the params. Verified that this works properly with versions 0.88 or lower

Steps to reproduce

Clone this example repo and run app.py
https://github.com/akshanshkmr/streamlit-multipage

My MultiPage Framework:

import streamlit as st

class MultiPage:
    def __init__(self):
        self.apps = []
        self.app_names = []
        self.default = ''

    def add_app(self, title, func, args=None):
        self.app_names.append(title)
        self.apps.append({
            "title": title,
            "function": func,
            "args":args
        })

    def run(self):
        # get query_params
        query_params = st.experimental_get_query_params()
        self.default = query_params["app"][0] if "app" in query_params else None
        default_index = self.app_names.index(self.default) if self.default else 0
        # simple radio button for navigation
        app = st.sidebar.radio(
            'Go To',
            self.apps,
            index = default_index,
            format_func=lambda app: app['title'],
            key = 'Navigation')
        # reflect the current app in query_params
        self.default = app['title']
        st.experimental_set_query_params(app=self.default)
        # runs the selected app with passes args
        app['function'](app['args'])

(Please provide a code snippet! This will help expedite us finding and solving the problem.)

If applicable, please provide the steps we should take to reproduce the bug:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'

Expected behavior:

Query params should be updated with 1 click on the radio button

Actual behavior:

User needs to click twice on each navigation option to update the query params

Is this a regression?

That is, did this use to work the way you expected in the past?
yes

Debug info

  • Streamlit version: 0.89
  • Python version: 3.9.2
  • PipEnv
  • OS version: Windows 10 19043.1237
  • Browser version: Microsoft Edge Version 94.0.992.31 (Official build) (64-bit)

Additional information

behaviour with version 0.89
streamlit_0 89_bug

behaviour with version 0.88
streamlit_0 88

@akshanshkmr akshanshkmr added type:bug Something isn't working status:needs-triage Has not been triaged by the Streamlit team labels Sep 26, 2021
@vdonato
Copy link
Collaborator

vdonato commented Oct 7, 2021

Hi @akshanshkmr,

It turns out that this is expected (and admittedly unintuitive) behavior that was caused by a change to widget identity semantics for keyed widgets that we made in 0.89. There's a page in our documentation that was recently added to describe the semantics.

Additionally, there's some helpful discussion in this comment as well as this issue that hopefully helps to explain why this behavior occurs as well as provides a code snippet that's useful in restructuring your code to avoid this.

@vdonato vdonato closed this as completed Oct 7, 2021
@akshanshkmr
Copy link
Author

Thanks for the reply @vdonato

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:needs-triage Has not been triaged by the Streamlit team type:bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants