在 Shiny Navbar App 中单击按钮更改标题

更改 Shiny 应用程序标题的好方法是什么?在下面的示例应用程序中,我有一个radioButtons输入,我希望应用程序标题(“项目标题”)在无线电选择的情况下进行更改。


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)


千万里不及你
浏览 107回答 2
2回答

FFIVE

library(shiny)js <- "$(document).ready(function(){&nbsp; $('#title_change').on('change', function(){&nbsp; &nbsp; var title = $('input[name=title_change]:checked').val();&nbsp; &nbsp; $('span.navbar-brand').text(title);&nbsp; });});"ui <- fluidPage(&nbsp; tags$head(tags$script(HTML(js))),&nbsp; navbarPage(&nbsp; &nbsp; "Project Title",&nbsp; &nbsp; tabPanel(&nbsp; &nbsp; &nbsp; title = "Tab 1",&nbsp; &nbsp; &nbsp; radioButtons("title_change", label = "Change title of App", choices = c("Title 1", "Title 2"))&nbsp; &nbsp; )&nbsp; ))server <- function(input, output) {}shinyApp(ui = ui, server = server)

蛊毒传说

你可以用一个shiny::textOutput和shiny::renderTextlibrary(shiny)ui <- navbarPage(textOutput("title"),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;tabPanel(title = "Tab 1",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; radioButtons("title_change", label = "Change title of App", choices = c("Title 1", "Title 2"))&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;))server <- function(input, output) {&nbsp; &nbsp; output$title <- renderText({&nbsp; &nbsp; &nbsp; &nbsp; input$title_change&nbsp; &nbsp; })}shinyApp(ui = ui, server = server)当您更改单选按钮时,它会更改input$title_change. 当它发生变化时,它会更新output$title.
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript