Search code examples
rshinyshinydashboard

Adding figure caption to figure inside tabPanel in shinydashboard


How do I properly add a figure text to a figure placed inside a tabPanel? I have tried the following, but the text does not align within the tabPanel box.

tabBox(
  tabPanel(
    "name",
    fluidRow(
      plotlyOutput("plot", width = "100%", height = "65vh")
    ),
    fluidRow(
      HTML("This is the caption text.")
    )
  )
)

Is there another way to do this correctly?


Solution

  • With only seeing a piece of your code, it's really hard to tell what you're seeing or what you'd like changed. However, from the experimenting I did, the fluidRow's within the the tabPanel seemed to cause both the plot and text to render outside of the tabPanel. Removing both instances of fluidRow fixed it for me.

    ui <- shinydashboard::dashboardPage(
        shinydashboard::dashboardHeader(title = "title"),
        shinydashboard::dashboardSidebar(),
        shinydashboard::dashboardBody(
            shinydashboard::tabBox(
                title = "title",
                shiny::tabPanel(
                    "name",
                    plotly::plotlyOutput("plot", width = "100%", height = "65vh"),
                    shiny::tags$p("This is the caption text.")
                )
            )
        )
    )
    
    server <- function(input, output, session) {
        output$plot <- plotly::renderPlotly({
            plotly::plot_ly(data = iris, x = ~Sepal.Length, y = ~Petal.Length)
        })
    }
    
    shiny::shinyApp(ui, server)
    

    ex