Adrian Adrian -4 years ago 69
R Question

R: how to add text to splitLayout

server <- function(input, output) {
output$plot1 <- renderPlot(plot(cars, main = "Cars"))
output$plot2 <- renderPlot(plot(pressure, main = "Pressure"))
output$plot3 <- renderPlot(plot(AirPassengers))

# Equal sizing
ui <- splitLayout(
shinyApp(ui, server)

Here I have a splitLayout with 2 plots, and on top of each plot, I want to be able to insert a caption, i.e. "Data 1" on top of
and "Data 2" on top of
. Is there an easy way to add captions? I've tried
but that didn't work out. Wondering if there's an easier way?

Answer Source

You can just put a tagList inside the split containers with literal values

ui <- splitLayout(
  tagList(tags$p("plot 1"), plotOutput("plot1")),
  tagList(tags$p("plot 2"), plotOutput("plot2"))

or you can add textOuputs

ui <- splitLayout(
  tagList(textOuput("plot1label"), plotOutput("plot1")),
  tagList(textOuput("plot2label"), plotOutput("plot2"))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download