Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change title on button click in Shiny Navbar App

What is a good way to change a Shiny app title? In the example app below I have a radioButtons input and I'd like the app title ("Project Title") to change given the radio selection.

library(shiny)

ui <- navbarPage("Project Title",
        tabPanel(title = "Tab 1",
                   radioButtons("title_change", label = "Change title of App", choices = c("Title 1", "Title 2"))
                   )
                 
)

server <- function(input, output) {
  
}

shinyApp(ui = ui, server = server)
like image 650
Ljupcho Naumov Avatar asked Jan 24 '26 12:01

Ljupcho Naumov


1 Answers

You can do this with a shiny::textOutput and shiny::renderText

library(shiny)
ui <- navbarPage(textOutput("title"),
                 tabPanel(title = "Tab 1",
                          radioButtons("title_change", label = "Change title of App", choices = c("Title 1", "Title 2"))
                 )
)
server <- function(input, output) {
    output$title <- renderText({
        input$title_change
    })
}
shinyApp(ui = ui, server = server)

When you change your radio button, that changes input$title_change. When that changes, it updates output$title.

like image 95
Zach Ingbretsen Avatar answered Jan 27 '26 01:01

Zach Ingbretsen