posit-dev / posit-dev/py-shiny

Should have version of `isolate()` which takes a function as an argument

Open
#436 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
1.8k
Forks
135
Avg merge
2d 18h
Merged PRs (30d)
21

Description

The existing with isolate(): syntax is good for running blocks of code, but it is not convenient when you simply want to get a value and use it in line. For example, suppose we want to get the value of `input.x

@output
@render.text
def txt():
    with isolate():
        capitalize = input.capitalize()
    if capitalize:
        return input.txt().upper()
    else:
        return input.txt()

In many cases, we just want to fetch a reactive value (or reactive Calc) inline, but the with isolate(): syntax makes that clunky and requires an extra variable to store the result.

It would be nice to be able to simply pass a function to isolate(), or perhaps a different function with a name like run_isolated().

For example:

@output
@render.text
def txt():
    if run_isolated(input.capitalize):
        return input.txt().upper()
    else:
        return input.txt()

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the existing isolate() implementation and its surrounding reactive entry points. Compare the requested callable form with the current with isolate(): behavior, then determine the API and verification needed for inline isolated reads to return the callable's value without creating a temporary variable.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.