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

selectInput with value=NULL doesn't work #559

Closed
kismsu opened this issue Aug 1, 2014 · 1 comment
Closed

selectInput with value=NULL doesn't work #559

kismsu opened this issue Aug 1, 2014 · 1 comment
Milestone

Comments

@kismsu
Copy link

@kismsu kismsu commented Aug 1, 2014

selectInput with value = NULL doesn't work. This is a bug from 0.10.1, as I've just updated. This is very sad, as some JS charts have default value = null.

library(shiny)
runApp(list(
    ui = pageWithSidebar(
        headerPanel("Shiny"),
        sidebarPanel(
            selectInput("list", "List with Null", list("Default" = NULL, "Item 1" = "Item_1") )
        ),
        mainPanel(
            textOutput("result")
        )),
    server = function(input, output, session){
        output$result<-renderText({
            input$list
        })
    }
))
@wch
Copy link
Collaborator

@wch wch commented Aug 29, 2014

Unfortunately, I don't think it's possible to get this to do what you want. All of the input items are converted to strings in the HTML, like so:

<option value="Item_1">Item 1</option>

And there's no straightforward way to set value to a null value. I think the way to go is to set it to a string value and use a reactive to convert that value into whatever you want. For example:

library(shiny)
runApp(list(
    ui = pageWithSidebar(
        headerPanel("Shiny"),
        sidebarPanel(
            selectInput("list", "List with Null", list("Default" = "null", "Item 1" = "Item_1") )
        ),
        mainPanel(
            textOutput("result")
        )),
    server = function(input, output, session){
        listVal <- reactive({
          if (identical(input$list, "null"))
            NULL
          else 
            input$list
        })

        output$result<-renderText({
            listVal()
        })
    }
))

@wch wch closed this as completed Aug 29, 2014
@yihui yihui added this to the 0.10.2 milestone Aug 29, 2014
@yihui yihui added the invalid label Aug 29, 2014
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