Reputation: 1939
The box title is usually set in ui.R. Is it possible to change the box title dynamically in server.R?
ui.R
box(title='Dynamic title here', plotOutput('barPlot'))
server.R
output$barPlot= renderPlot({...})
# Can I dynamically change the box title here?
Edit:
Here's a simple code to try
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)
Upvotes: 2
Views: 3925
Reputation: 6913
Try this out, using 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)
Upvotes: 4