Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

shiny: dynamically change tab names

I'm working on a Shiny application that is supposed to handle multiple languages. I managed to dynamically translate almost all elements of the app depending on a selectInput to choose the language. However the "hard stuff" remains the navbarPage tabs as well as the tabPanels inside my pages. I cannot change their names. I tried this, but it does not work:

library(shiny)
ui <- navbarPage("App Title",
                 tabPanel("tab1", 
                          selectInput("language", "language", c("EN", "FR"), width = '300px'),
                          textOutput("text")),
                 uiOutput("render_tab2"))
server <- function(input, output, session) {
  output$text = renderText({ switch(input$language, "EN"="hello world", "FR"="bonjour monde")  })
  output$render_tab2 = renderUI({
    tabPanel( title=switch(input$language, "EN"="tab2", "FR"="onglet2") )})}
shinyApp(ui, server)

And the updatenavbarpanel() family of functions are just to set the active tab, not change their characteristics...Is there a way to do it, if possible that does not change the structure of all my app... THanks a lot.

like image 820
agenis Avatar asked Dec 19 '17 23:12

agenis


1 Answers

This piece of code set the title dynamically :

library(shiny)
ui <- navbarPage("App Title",
                 tabPanel(title = uiOutput("title_panel"), 
                          selectInput("language", "language", c("EN", "FR"), width = '300px')
                )
    )

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

    output$title_panel = renderText({
        switch(input$language, "EN"="hello world", "FR"="bonjour monde") 
    })
}

shinyApp(ui, server)

Edit : Works with both uiOutput("title_panel") & textOutput("title_panel")

like image 176
qfazille Avatar answered Oct 27 '22 16:10

qfazille