Jana P
Jana P

Reputation: 25

Is there a R function in shiny to search items

I have a below code. I need to put search aspects under operations tab. Can I add it to the below code. The reason is if there are many items under operations, I may need to search

# faithful is the dataset
sample1 <- 1:3
library(shiny)
ui <- fluidPage(
  sidebarLayout(
    sidebarPanel(
      selectInput(
        "x", 
        "Operations", 
        choices = c("summary", "stem", "typeof", "mode", "birth")
      )
    ), 
    mainPanel(
      h6("Here it is"), 
      verbatimTextOutput("message")
    )
  )
)

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

    output$message <- renderPrint({
        if(input$x == "summary") {
            summary(faithful$eruptions)
        } else if (input$x == "stem") {
            print(stem(faithful$eruptions))
        } else if (input$x == "typeof") {
            typeof(sample1)
        } else if (input$x == "mode") {
            mode(sample1)
        } 
    })
}

shinyApp(ui, server)

Upvotes: 0

Views: 108

Answers (1)

One alternative could be to use selectize = TRUE in the selectInput, then the user can type part of the choice and it'll find it just like in a search button, instead of just having a list of choices that cant be filtered.

Please check the last example of this link.

Upvotes: 1

Related Questions