posit-dev / posit-dev/py-shiny
Unexpected behaviour of reactive.calc
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.8k
- Forks
- 135
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 21
Description
Hello,
I would like to report something that generated unexpected behaviour within a reactive.calc. I have condensed my original problem to a reprex, so some of it might seem a little convoluted but it reproduces the issue
from shiny import reactive
from shiny.express import input, render, ui, session
import random
@reactive.effect
@reactive.event(input.modal)
def _():
m = ui.modal(
ui.input_text("new", "New"),
ui.input_action_button("add", "Add"),
easy_close=True,
footer=None,
)
ui.modal_show(m)
@reactive.calc
@reactive.event(input.add)
def processNew():
#Do something ...
ui.modal_remove()
return
@reactive.calc
@reactive.event(input.btn, processNew)
def textOut():
return "Your random number is: " + str(random.random())
ui.input_action_button("btn", "Generate")
ui.input_action_button("modal", "Input")
@render.text
def _():
return textOut()
When you execute this code, nothing happens if you click the "generate" button. However, as soon as you have used the "Add" button once, it starts working. This most likely is because of the modal window not being there at the start, but this should not prevent the textOut() function from running when input.btn is clicked before the modal is shown for the first time.
Thanks for looking into this
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the supplied minimal Python reprex and tracing the reactive.calc and reactive.event dependencies around processNew and textOut. No repository files or tests are named in the report; done means clicking Generate updates the output before the modal is opened, while the existing Add-button behavior remains correct.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100