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

UI not updating when setting reactive value (pn.rx) to the empty string #6302

Closed
MarcSkovMadsen opened this issue Feb 4, 2024 · 1 comment · Fixed by #6303
Closed

UI not updating when setting reactive value (pn.rx) to the empty string #6302

MarcSkovMadsen opened this issue Feb 4, 2024 · 1 comment · Fixed by #6303
Labels
type: bug Something isn't correct or isn't working
Milestone

Comments

@MarcSkovMadsen
Copy link
Collaborator

MarcSkovMadsen commented Feb 4, 2024

I'm on panel==1.3.8. I'm trying to update a UI progressively using pn.rx for the basic tutorial. But I'm experiencing an issue with the UI not updating when setting a reactive value (pn.rx) to the empty string.

result.rx.value="" # This line does not update the UI
result.rx.value="Some Value" # This line does update the UI

Reproducible Example

import panel as pn
from time import sleep
import random

pn.extension()

OPTIONS = ["Wind Turbine", "Solar Panel", "Battery Storage"]

# State

result = pn.rx("")
is_running = pn.rx(False)

# Transformations

def classify(image):
    sleep(2)
    return random.choice(OPTIONS)

has_result = result.rx.pipe(bool)

def _show_submit_message(result, is_running):
    return not result and not is_running

show_submit_message=pn.rx(_show_submit_message)(result, is_running)

def run_classification(_):
    result.rx.value=""
    is_running.rx.value=True
    prediction = classify(None)
    result.rx.value = f"Its a {prediction}"
    is_running.rx.value=False
    # result.rx.value=""

# Inputs: Widgets

run = pn.widgets.Button(name="Submit", button_type="primary", on_click=run_classification)

# Outputs: Views

click_submit = pn.pane.Markdown("Click Submit", visible=show_submit_message)
progress_message = pn.Row(
    pn.indicators.LoadingSpinner(
        value=True, width=25, height=25, align="center", margin=(5, 0, 5, 10)
    ),
    pn.panel("Running classifier ...", margin=0),
    visible=is_running
)

pn.Column(run, click_submit, result, progress_message).servable()

When I click the button the second, third etc. time, I would expect the result string be reset to "" in the UI at the start of the classification. But it does not happen as you can see in the video below.

reset-not-working.mp4

Alternative Version

We can also set the result to "" at the end of the classification to make the issue more clear. Instead the intermediate result "Its a Solar Panel" or similar is shown!

import panel as pn
from time import sleep
import random

pn.extension()

OPTIONS = ["Wind Turbine", "Solar Panel", "Battery Storage"]

# State

result = pn.rx("")
is_running = pn.rx(False)

# Transformations

def classify(image):
    sleep(2)
    return random.choice(OPTIONS)

has_result = result.rx.pipe(bool)

def _show_submit_message(result, is_running):
    return not result and not is_running

show_submit_message=pn.rx(_show_submit_message)(result, is_running)

def run_classification(_):
    result.rx.value=""
    is_running.rx.value=True
    prediction = classify(None)
    result.rx.value = f"Its a {prediction}"
    is_running.rx.value=False
    result.rx.value=""

# Inputs: Widgets

run = pn.widgets.Button(name="Submit", button_type="primary", on_click=run_classification)

# Outputs: Views

click_submit = pn.pane.Markdown("Click Submit", visible=show_submit_message)
progress_message = pn.Row(
    pn.indicators.LoadingSpinner(
        value=True, width=25, height=25, align="center", margin=(5, 0, 5, 10)
    ),
    pn.panel("Running classifier ...", margin=0),
    visible=is_running
)

pn.Column(run, click_submit, result, progress_message).servable()
not-working2.mp4
@MarcSkovMadsen MarcSkovMadsen added the type: bug Something isn't correct or isn't working label Feb 4, 2024
@MarcSkovMadsen MarcSkovMadsen added this to the next milestone Feb 4, 2024
@philippjfr
Copy link
Member

Nothing to do with rx it turns out, HTML and other markup panes apparently couldn't be emptied at all.

@philippjfr philippjfr modified the milestones: next, v1.4.0 Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't correct or isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants