问题
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