Change the title by pressing a shiny button Shiny R

一世执手 提交于 2021-02-11 14:22:47

问题


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)

How to change the title when pressing a button? the idea is to change the word free to busy when the button is pressed.


回答1:


Would make the h1 header using uiOutput in the ui. Then, you can dynamically change this text to whatever you want in server. Perhaps for your example, you can have a reactiveVal that contains the text you want in the header, which can be modified in your case when the actionButton is pressed.

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)


来源:https://stackoverflow.com/questions/63060893/change-the-title-by-pressing-a-shiny-button-shiny-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!