闪亮:动态更改选项卡名称 [英] shiny: dynamically change tab names

查看:76
本文介绍了闪亮:动态更改选项卡名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个可以处理多种语言的 Shiny 应用程序.我设法根据 selectInput 来动态翻译应用程序的几乎所有元素来选择语言.然而,硬东西"仍然是我页面中的 navbarPage 标签以及 tabPanels.我不能改变他们的名字.我试过这个,但它不起作用:

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)

updatenavbarpanel() 系列函数只是设置活动选项卡,而不是改变它们的特性......有没有办法做到这一点,如果可能的话,不改变其结构我所有的应用程序...非常感谢.

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.

推荐答案

这段代码动态设置标题:

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)

适用于 uiOutput("title_panel") &textOutput("title_panel")

这篇关于闪亮:动态更改选项卡名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆