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

updateSelectizeInput label is broken in shiny 1.2 #2245

Closed
aslomko opened this issue Nov 4, 2018 · 1 comment · Fixed by #2248
Closed

updateSelectizeInput label is broken in shiny 1.2 #2245

aslomko opened this issue Nov 4, 2018 · 1 comment · Fixed by #2248
Milestone

Comments

@aslomko
Copy link

aslomko commented Nov 4, 2018

updateSelectizeInput changing the label does not work in shiny 1.2. Please see example:

#
# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#
# Find out more about building applications with Shiny here:
#
#    http://shiny.rstudio.com/
#

library(shiny)

# Define UI for application that draws a histogram
ui <- fluidPage(
   useShinyjs(),
   # Application title
   titlePanel("Old Faithful Geyser Data"),
   # Sidebar with a slider input for number of bins 
   sidebarLayout(
      sidebarPanel(
         sliderInput("bins",
                     "Number of bins:",
                     min = 1,
                     max = 50,
                     value = 30),
         actionButton('testb','Button'),
         selectizeInput("test","Select",choices=c("Apple","Banana","Pineapple"),options=list(create=T))
      ),
      
      # Show a plot of the generated distribution
      mainPanel(
         plotOutput("distPlot")
      )
   )
)

# Define server logic required to draw a histogram
server <- function(input, output,session) {
  
  observeEvent(input$testb,{
    updateSelectizeInput(session,"test",label="SelectMore",choices=c("Pinecone","Mashmallow","Candy"))
  })
   
   output$distPlot <- renderPlot({
      # generate bins based on input$bins from ui.R
      x    <- faithful[, 2] 
      bins <- seq(min(x), max(x), length.out = input$bins + 1)
      
      # draw the histogram with the specified number of bins
      hist(x, breaks = bins, col = 'darkgray', border = 'white')
   })
}

# Run the application 
shinyApp(ui = ui, server = server)


@wch
Copy link
Collaborator

wch commented Nov 5, 2018

Simplified example:

library(shiny)

ui <- fluidPage(
  actionButton('testb','Button'),
  selectizeInput("test", "Original label", choices=c("Apple","Banana","Pineapple"))
)

server <- function(input, output,session) {
  observeEvent(input$testb,{
    updateSelectizeInput(session, "test", label="New label",
      choices = c("Pinecone","Mashmallow","Candy"))
  })
}

shinyApp(ui = ui, server = server)

It looks like the recent version of Selectize.js changes the for attribute to "test-selectized":

<label class="control-label" for="test-selectized">Original label</label>

See:
https://github.com/selectize/selectize.js/blob/5f3f3c1/src/selectize.js#L142-L145
selectize/selectize.js#755
selectize/selectize.js#1119

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 a pull request may close this issue.

3 participants