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

Should add current URL hash to clientData #1418

Closed
wch opened this issue Oct 12, 2016 · 4 comments
Closed

Should add current URL hash to clientData #1418

wch opened this issue Oct 12, 2016 · 4 comments
Assignees

Comments

@wch
Copy link
Collaborator

wch commented Oct 12, 2016

Currently, clientData only contains the initial URL hash, but it doesn't have the current URL hash. This is because not all browsers at the time supported the onhashchange event. See the comment here:
https://github.com/rstudio/shiny/blob/9613c58/srcjs/init_shiny.js#L412-L416

Pretty much all browsers these days support it, even IE8. See:
http://caniuse.com/#search=onhashchange
http://benalman.com/projects/jquery-hashchange-plugin/

@daattali
Copy link
Contributor

I'm used to the assumption that session$clientData only runs once for each session, when the session begins. Would this be the only case where clientData can get updated during a session? Or was my previous assumption wrong

@wch
Copy link
Collaborator Author

wch commented Oct 12, 2016

session$clientData is a reactiveValues object. Some of the things don't change, but there are things that do. See here: https://github.com/rstudio/shiny/blob/7aacf9c/R/shiny.R#L206-L212

@bborgesr bborgesr self-assigned this Nov 17, 2016
@bborgesr
Copy link
Contributor

@wch this is about to be merged in the pseudo-nav PR (#1447). Here's the sample app (using the barbara@pushstate branch) -- also in documentation, see ?getUrlHash:

  ## Printing the value of the URL hash
  ## (Use the back and forward buttons to see how the browser
  ## keeps a record of each state)
  shinyApp(
    ui = fluidPage(
      textInput("txt", "Enter new hash"),
      helpText("Format: #hash"),
      actionButton("go", "Update"),
      hr(),
      verbatimTextOutput("hash")
    ),
    server = function(input, output, session) {
      observeEvent(input$go, {
        updateQueryString(input$txt, mode = "push")
      })
      output$hash <- renderText({
        hash <- getUrlHash()
        paste("Your hash is:\n", hash)
      })
    }
  )

What do you think?

@bborgesr
Copy link
Contributor

Closed in #1447 via a0b917a

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

No branches or pull requests

3 participants