Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Render title in R shiny box dynamically

Tags:

r

shiny

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")
       }
 })
like image 833
SNT Avatar asked Oct 24 '25 22:10

SNT


1 Answers

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!


enter image description here


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)
like image 97
Florian Avatar answered Oct 27 '25 14:10

Florian