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

feat: Create Session.set_message_handler(name, handler) #1253

Merged
merged 8 commits into from
Mar 27, 2024

Conversation

schloerke
Copy link
Collaborator

Sets a method that can be called by the client via Shiny.shinyapp.makeRequest(). Shiny.shinyapp.makeRequest() makes a request to the server and waits for a response. By using makeRequest() (JS) and set_message_handler() (python), you can have a much richer communication interaction than just using Input values and re-rendering outputs.

For example, @render.data_frame can have many cells edited. While it is possible to set many input values, if makeRequest() did not exist, the data frame would be updated on the first cell update. This would cause the data frame
to be re-rendered, cancelling any pending cell updates. makeRequest() allows for individual cell updates to be sent to the server, processed, and handled by the existing data frame output.


Removes Session._output_binding_request_handler() and all methods used to support it.

Now, there is no coincidences and users opt-in directly to the method:

Ex:

        ...
        request_key = session.set_message_handler(
            f"data_frame_patches_{self.output_id}",
            handler_fn,
        )

The request_key is then set to the client so that it know where it can make requests. The request_key is namespaced by the session, so authors do not need to handle it themselves.

shiny/session/_session.py Outdated Show resolved Hide resolved
shiny/session/_session.py Outdated Show resolved Hide resolved
@schloerke schloerke marked this pull request as ready for review March 27, 2024 15:55
@schloerke schloerke merged commit 10b8e68 into main Mar 27, 2024
32 checks passed
@schloerke schloerke deleted the data_frame_message_handler branch March 27, 2024 16:06
schloerke added a commit that referenced this pull request Mar 27, 2024
* main:
  feat: Create `Session.set_message_handler(name, handler)` (#1253)
  Fix input name
  Enable error console when running locally. (#1060)
  test: Update test to use variable, not capture stdout (#1236)
schloerke added a commit that referenced this pull request Mar 28, 2024
* main:
  test(CI): Add merge queue support for faster PR testing (#1265)
  fix(panel_conditional): Include `.shiny-panel-conditional` class (#1257)
  feat: Create `Session.set_message_handler(name, handler)` (#1253)
  Fix input name
  Enable error console when running locally. (#1060)
  test: Update test to use variable, not capture stdout (#1236)
  test: Fix deploys for shinyapps.io and connect (#1224)
  chore(test): Playwright test refactors and clean up (#1204)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants