I am trying to render the title for the boxes I am using in R shiny dynamically.
As of now the box code looks like this
box( title = "lorem ipsum",
width = 6,
solidHeader = TRUE,
status = "primary",
tableOutput("consumption"),
collapsible = T
)
Is it possible to use render text in server and pass the text as a title:
con1 <- renderText({
if (age() == FALSE)
{
return("lorem1")
}
else
{
return("lorem2")
}
})
You should store the output of renderText as output$x where x is arbitrary, so you can refer to that element as textOutput('x') in the title parameter of your box. So a working example would be as shown below. Hope this helps!

library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
checkboxInput('mybox',label = 'Title'),
box(title=textOutput('title'),
width = 6,
solidHeader = TRUE,
status = "primary",
p('Use the checkbox to change the title of this box.')
)
)
)
server <- function(input, output) {
output$title <- renderText({ifelse(!input$mybox,'Title 1','Title 2')})
}
shinyApp(ui,server)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With