rshinyshinydashboard

How to use selectInput to set a box title?


I want to use selectInput to set the title on a box. For example, I would like the default title to be: Name 2 settings

Right now, I'm able to get the title to be [1] "Name 2 settings". Is there a way to remove the [1] and the quotes?

This is my sample app:

## app.R ##
library(shiny)
library(shinydashboard)

ui <- dashboardPage(dashboardHeader(),
                    dashboardSidebar(),
                    dashboardBody(fluidRow(
                      box(
                        title = "Settings", width = 6, solidHeader = TRUE, status = "primary",
                        flowLayout(selectInput(
                          "Design", "Design:",
                          c("Name 1" = "Name 1",
                            "Name 2" = "Name 2"),
                          selected = "Name 2"
                        ))
                      ),
                      box(
                        title = textOutput("Design"), width = 4, solidHeader = TRUE, status = "primary",
                        "Box content"
                      )
                    )))
server <- function(input, output) {
  output$Design <- renderPrint({
    paste(input$Design, 'settings')
  })
}

shinyApp(ui, server)

Solution

  • Just replace renderPrint with renderText:

    server <- function(input, output) {
        output$Design <- renderText({
            paste(input$Design, 'settings')
        })
    }