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(clientdata): Add viewport and scrollable size values to clientdata #4147

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

karangattu
Copy link

@karangattu karangattu commented Oct 22, 2024

What is this PR about?

Add viewport height & width along with scrollable area height and width to the clientdata.

DEMO

demo_resize

Example App

library(shiny)
library(bslib)

ui <- bootstrapPage(
  h3("URL components"),
  verbatimTextOutput("urlText"),

  h3("Parsed query string"),
  verbatimTextOutput("queryText")
)

server <- function(input, output, session) {

  # Return the components of the URL in a string:
  output$urlText <- renderText({
    paste(sep = "",
          "protocol: ", session$clientData$url_protocol, "\n",
          "hostname: ", session$clientData$url_hostname, "\n",
          "pathname: ", session$clientData$url_pathname, "\n",
          "port: ",     session$clientData$url_port,     "\n",
          "search: ",   session$clientData$url_search,   "\n",
          "width: ",    session$clientData$window_width, "\n",
          "height: ",   session$clientData$window_height, "\n",
          "scroll_width: ",  session$clientData$scroll_width, "\n",
          "scroll_height: ", session$clientData$scroll_height, "\n"
    )
  })

  # Parse the GET query string
  output$queryText <- renderText({
    query <- parseQueryString(session$clientData$url_search)

    # Return a string with key-value pairs
    paste(names(query), query, sep = "=", collapse=", ")
  })
}

shinyApp(ui, server)

Testing done

Verified that the values in clientdata are updated anytime the browser is resized. Tested it on Chrome, Firefox and Safari browsers on MacOS.

Documentation added

  • Added entry in NEWS.md file
  • Make changes in the website with this PR

@karangattu karangattu requested a review from wch October 22, 2024 19:58
srcts/src/shiny/index.ts Outdated Show resolved Hide resolved
srcts/src/shiny/index.ts Outdated Show resolved Hide resolved
srcts/src/shiny/index.ts Outdated Show resolved Hide resolved
@karangattu karangattu requested a review from cpsievert October 31, 2024 17:26
@gadenbuie gadenbuie added this to the Next Release milestone Nov 13, 2024
@gadenbuie gadenbuie modified the milestones: v1.10.0, Next Release Dec 6, 2024
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.

3 participants