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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug with renderUI when bookmarking: inputs created dynamically keep reverting back to the bookmarked value #2322

Closed
daattali opened this issue Feb 7, 2019 · 3 comments
Labels
Feature: Bookmarking Priority: High Type: Regression Functionality from a previous release no longer works
Milestone

Comments

@daattali
Copy link
Contributor

daattali commented Feb 7, 2019

This one took quite a while to isolate and find the issue 馃

Here's the simplest example I could think of. Using this shiny app:

library(shiny)

ui <- function(req) {
  fluidPage(
    bookmarkButton(),
    numericInput("num", "Number", 3),
    uiOutput("rows")
  )
}

server <- function(input, output, session) {
  output$rows <- renderUI({
    lapply(seq(input$num), function(idx) {
      textInput(paste0("text_", idx), paste("Input", idx), "test")
    })
  })
}

shinyApp(ui, server, enableBookmarking = "url")

The numeric input controls how many text inputs are shown. Every time you change the number, the text inputs are re-rendered, with the default value of "test". This is fine initially when you run the app unless the app is restored from a bookmark.

The problem:

Change any of the text fields, and bookmark the URL. Now load the app using this bookmarked URL. The app will correctly load into the last state. If you change the number however, the text inputs are now going to be initialized using the values that they had when you restored the app from the bookmark, instead of using the values that the server code is telling them to have.

This is most likely happening because of the call to restoreInput() inside the text input, which essentially makes the renderUI ignore the value that we pass and just go back to the bookmarked state.

@daattali
Copy link
Contributor Author

daattali commented Feb 7, 2019

Actually this can be reproduced in a much simpler app:

library(shiny)

ui <- function(req) {
  fluidPage(
    bookmarkButton(),
    uiOutput("out"),
    actionButton("go", "Go")
  )
}

server <- function(input, output, session) {
  output$out <- renderUI({
    input$go
    textInput("text", "Text", "text")
  })
}

shinyApp(ui, server, enableBookmarking = "url")

Pressing the button should re-render the input with "text". After restoring from a bookmark, it will instead always render the input with the bookmarked value.

image

@alandipert
Copy link
Contributor

Thanks @daattali, I reproduced. I strongly suspect this was introduced by 0bb53e8

@alandipert alandipert added this to the 1.2.1 milestone Mar 22, 2019
@alandipert alandipert added Priority: High Type: Regression Functionality from a previous release no longer works Feature: Bookmarking labels Mar 22, 2019
@alandipert alandipert modified the milestones: 1.2.1, 1.3 Mar 22, 2019
@wch
Copy link
Collaborator

wch commented Mar 26, 2019

Fixed in the rc-v1.3.0 branch by #2360.

@wch wch closed this as completed Mar 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature: Bookmarking Priority: High Type: Regression Functionality from a previous release no longer works
Projects
None yet
Development

No branches or pull requests

3 participants