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

时间:2016-02-22 08:46:26

标签: r shiny

框标题通常在ui.R中设置。是否可以在server.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) #我可以在这里动态更改框标题吗?

修改

这是一个简单的代码尝试

(def yip-shape
  (insta/parser
   (str/join "\n"
             ["S = ( list-item | heading | text-block )*"

              ;; lists and that
              "list-item = list-level <ws> anything"
              "list-level = #' {0,3}\\*'"

              ;; headings
              "heading = heading-level <ws> ( heading-keyword <ws> )? ( heading-date <ws> )? anything <eol?>"
              "heading-level = #'#{1,6}'"
              "heading-date = <'<'> #'[\\d-:]+' <'>'>"
              "heading-keyword = 'TODO' | 'DONE'"

              "text-block = anything*"

              "anything = #'.+'"
              "<eol> = '\\r'? '\\n'"
              "<ws> = #'\\s+'"])))

1 个答案:

答案 0 :(得分:4)

使用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)