【问题标题】:Change the title by pressing a shiny button Shiny R按闪亮按钮 Shiny R 更改标题
【发布时间】:2020-07-24 02:55:00
【问题描述】:
library(shiny)

ui <- fluidPage(
  h1("Free",align = "center"),
  actionButton("go", "Go") 
 )

server <- function(input, output) {

 observeEvent(input$go,{
#change the h1 title for 
code("Busy",align="center")
}
}
shinyApp(ui, server)

按下按钮时如何更改标题?这个想法是在按下按钮时将单词 free 更改为 busy。

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    将在ui 中使用uiOutput 制作h1 标头。然后,您可以在server 中将此文本动态更改为您想要的任何内容。也许对于您的示例,您可以有一个 reactiveVal 在标题中包含您想要的文本,当您按下 actionButton 时,可以根据您的情况对其进行修改。

    library(shiny)
    
    ui <- fluidPage(
      uiOutput("text_header"),
      actionButton("go", "Go") 
    )
    
    server <- function(input, output) {
      
      rv <- reactiveVal("Free")
      
      observeEvent(input$go, {
        rv("Busy")
      })
      
      output$text_header <- renderUI({
        h1(rv(), align = "center")
      })
      
    }
    
    shinyApp(ui, server)
    

    【讨论】:

    • 我对reactivevalues不是很熟悉,我会进一步研究,非常感谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-29
    • 2013-03-22
    • 2015-04-26
    • 1970-01-01
    • 1970-01-01
    • 2018-05-14
    相关资源
    最近更新 更多