Skip to content

Widgets' inputIds behave incorrectly with spaces #2799

Open
@jntrcs

Description

@jntrcs

With my non-comprehensive look through Shiny documentation, it appears that the only requirement for a Shiny widget inputId is that it is a character string. However, I have discovered that if you have spaces in that character string, the updateWidget function doesn't behave properly (it basically is ignored, with no error message). My simple repro, where I change the id from "bin" to "Number of bins" documents the problem:

library(shiny)
ui <- fluidPage(
    sidebarLayout(
        sidebarPanel(
            sliderInput("Number of bins",
                        "Number of bins:",
                        min = 1,
                        max = 50,
                        value = 30),
            actionButton("IncreaseBins", "Increase max number of bins")
        ),
        mainPanel(
           plotOutput("distPlot")
        )
    )
)

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

    output$distPlot <- renderPlot({
        x    <- faithful[, 2]
        bins <- seq(min(x), max(x), length.out = input[["Number of bins"]] + 1)
        hist(x, breaks = bins, col = 'darkgray', border = 'white')
    })
    observeEvent(input$IncreaseBins, {
        updateSliderInput(session, "Number of bins", max = 100)
    })
}

shinyApp(ui = ui, server = server)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions