繁体   English   中英

闪亮的应用程序:如何在server.R中动态更改框标题?

[英]Shiny App: How to dynamically change box title in server.R?

框标题通常在ui.R中设置。 是否可以在server.R中动态更改框标题?

ui.R

box(title='Dynamic title here', plotOutput('barPlot'))

server.R

output$barPlot= renderPlot({...}) #我可以在此处动态更改框标题吗?

编辑:

这是一个简单的代码尝试

ui <- fluidPage(
  fluidRow(
    column(width=6,
           box(
             title = 'Dynamic title',
             width = NULL,
             plotOutput('speed', height='100%')
           )
    )
  )
)

server <- function(input, output){
  output$speed <- renderPlot({
    plot(speed ~ dist, data = cars)
    # need a code to change the box title
  }, height=300)
}

shinyApp(ui=ui, server=server)

使用renderUI尝试renderUI

ui <- fluidPage(
  fluidRow(
    textInput("title", "What should the tile be?"),
    uiOutput("box1")
  )
)

server <- function(input, output){

  output$speed <- renderPlot({
    plot(speed ~ dist, data = cars)
  })

  output$box1 <- renderUI({
    validate(
      need(input$title, "Please enter a valid title!")
    )
    box(title = input$title, plotOutput("speed"))
  })
}

shinyApp(ui = ui, server = server)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM