Search code examples
rshinyshinydashboard

R shiny input widget


What kind of Shiny input widget can I use to implement a selector as in the picture? Is it an action button used?

enter image description here


Solution

  • With package shinyWidgets and a bit of CSS you can achieve the same result:

    library(shiny)
    library(shinyWidgets)
    
    ui <- fluidPage(
      tags$h1("Active background color for radioGroupButtons"),
      
      tags$style(
        ".btn-custom.active, .btn-custom:active, .btn-custom:focus, .btn-custom:hover {
          background: #4B088A !important;
          color: #FFF !important;
        }",
        ".btn-custom {border-color: #4B088A; color: #4B088A; background: #FFF;}"
      ),
      
      radioGroupButtons(
        inputId = "somevalue",
        label = NULL,
        choices = c("All cases", "Active cases"),
        status = "custom"
      ),
      verbatimTextOutput("value")
    )
    server <- function(input, output) {
      
      output$value <- renderPrint({ input$somevalue })
      
    }
    shinyApp(ui, server)