Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Oct 16, 2025

  • Implement allow_reconnect() method on Session abstract base class
  • Implement allow_reconnect() method on AppSession class
  • Implement allow_reconnect() method on SessionProxy class
  • Add method signature with proper type hints (Literal[True, False, "force"])
  • Use _send_message_sync() helper to send the allowReconnect message
  • Add input validation with ValueError for invalid values
  • Add comprehensive docstring with detailed behavior descriptions
  • Add @add_example decorator for documentation
  • Add changelog entry in UNRELEASED section
  • Create comprehensive test suite (4 test cases)
  • Create app-core.py example demonstrating feature
  • Create app-express.py example demonstrating feature
  • Update documentation based on R roxygen2 docs
  • Add stub method to ExpressStubSession
  • Fix linting issues (trailing whitespace)

Summary

Fixed trailing whitespace in example files to address linting requirements.

Original prompt

This section details on the original issue you should resolve

<issue_title>[Feature]: Support shiny server reconnections like in Shiny for R</issue_title>
<issue_description>### Category

Performance

Scope

Minor Enhancement

Problem

In Shiny for R, setting session$allowReconnect(TRUE) enables reconnection behavior to existing or new sessions whenever shiny server disconnects. I don't believe this exists at the moment for Shiny for Python.

On the Javascript console on a Shiny for Python app, running Shiny.shinyapp.$socket.close() then Shiny.shinyapp.reconnect() does seem to produce this behavior, but Shiny.shinyapp.allowReconnect = false and I'm unsure how to enable.

Solution

I would like the ability to set this from Python using the session object.

session.allow_reconnect(True)

and this would cause Shiny to behave similar to when it is enabled in R.

Alternatives (Optional)

No response

Example (Optional)

Impact (Optional)

No response

Contribution? (Optional)

None</issue_description>

<agent_instructions>In R, this was implemented using the allowReconnect on the Shiny Session object.

    allowReconnect = function(value) {
      if (!(identical(value, TRUE) || identical(value, FALSE) || identical(value, "force"))) {
        stop('value must be TRUE, FALSE, or "force"')
      }
      private$write(toJSON(list(allowReconnect = value)))
    },

Please implement this on the Session python class. It should use the _send_message_sync() helper method.

Add a changelog entry of the change</agent_instructions>

Comments on the Issue (you are @copilot in this section)

Fixes #2058


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@schloerke
Copy link
Collaborator

@copilot

Please add documentation to the method.

The roxygen2 docs from R were:

#' \item{allowReconnect(value)}{
#'   If `value` is `TRUE` and run in a hosting environment (Shiny
#'   Server or Connect) with reconnections enabled,  then when the session ends
#'   due to the network connection closing, the client will attempt to
#'   reconnect to the server. If a reconnection is successful, the browser will
#'   send all the current input values to the new session on the server, and
#'   the server will recalculate any outputs and send them back to the client.
#'   If `value` is `FALSE`, reconnections will be disabled (this is
#'   the default state). If `"force"`, then the client browser will always
#'   attempt to reconnect. The only reason to use `"force"` is for testing
#'   on a local connection (without Shiny Server or Connect).
#' }

@Copilot Copilot AI changed the title [WIP] Add support for shiny server reconnections in Python Add session.allow_reconnect() method to control client reconnection behavior Oct 16, 2025
@Copilot Copilot AI requested a review from schloerke October 16, 2025 18:09
Copilot finished work on behalf of schloerke October 16, 2025 18:09
Copy link
Contributor Author

Copilot AI commented Oct 16, 2025

@copilot

Please add documentation to the method.
...

Added comprehensive documentation based on the R roxygen2 docs. The docstring now explains the behavior in hosting environments (Posit Connect/Shiny Server) vs local connections, and clarifies when each value option should be used. (commit 1f43e56)

Copilot finished work on behalf of schloerke October 16, 2025 18:12
@schloerke
Copy link
Collaborator

@copilot Please add a stub method for ExpressStubSession

Copy link
Contributor Author

Copilot AI commented Oct 16, 2025

@copilot Please add a stub method for ExpressStubSession

Added stub method to ExpressStubSession class. (commit 6a16f9c)

Copilot finished work on behalf of schloerke October 16, 2025 18:35
@schloerke schloerke changed the title Add session.allow_reconnect() method to control client reconnection behavior feat(session): Add allow_reconnect() method to control client behavior on disconnect Oct 16, 2025
@schloerke
Copy link
Collaborator

@copilot Run make check-fix to fix any linting errors. If any lints could not be automatically addressed, please fix them as well.

Copy link
Contributor Author

Copilot AI commented Oct 16, 2025

@copilot Run make check-fix to fix any linting errors. If any lints could not be automatically addressed, please fix them as well.

Fixed linting issues by removing trailing whitespace from the example files. (commit d89f542)

@Copilot Copilot AI requested a review from schloerke October 16, 2025 18:43
Copilot finished work on behalf of schloerke October 16, 2025 18:43
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.

[Feature]: Support shiny server reconnections like in Shiny for R

2 participants