Conditional panel based on a selectInput with emoji

45 Views Asked by At

I have a SelectInput with text and emojis (using install.packages("devtools") , and then devtools::install_github("hadley/emo")).

I am trying to define a condition based on the choices:

library(shiny)
library(shinyWidgets)
library(stringi)

ui <- fluidPage(

  mainPanel(
    
    div(selectInput(inputId = "MySelection",
                    label = "Which choice ? :",
                    choices = c(
                                paste("No selection",
                                        stri_dup(intToUtf8(160), 3),
                                        emo::ji("sun")),
                                "Selection one",
                                "Selection two"
                                ),
                    width = '350px'
    )
    ),
    width = 3 
  ),
  
  conditionalPanel(
    condition = "input.MySelection.indexOf('No selection') > -1",
    "Test number 1"
  )
  
)


server <- function(input, output){
  output$ChoosenSection <- renderText({
    input$MySelection
    })
}

shinyApp(ui = ui, server = server)

However, the solution I found (with indexOf() > -1) is based on whether the choices contain some characters.

Instead, how can I ask for the exact value? In order to say it in human language:

condition = ‘ the choice is equal to : paste("No selection", stri_dup(intToUtf8(160), 3), emo::ji("sun")) ‘

1

There are 1 best solutions below

1
Stéphane Laurent On BEST ANSWER

For me it works with a named list:

ui <- fluidPage(
  
  mainPanel(
    
    div(selectInput(inputId = "MySelection",
                    label = "Which choice ? :",
                    choices = setNames(
                      1:3, 
                      c(
                        paste("No selection",
                              stri_dup(intToUtf8(160), 3),
                              emo::ji("sun")),
                        "Selection one",
                        "Selection two"
                      )),
                    width = '350px'
    )
    ),
    width = 3 
  ),
  
  conditionalPanel(
    condition = "input.MySelection.indexOf('1') > -1",
    "Test number 1"
  )
  
)