Search code examples
rbuttonshinydownloadshinydashboard

Add button next to tabs in R Shiny tabBox


I have a tabBox in a shiny dashboard and would like to add a download button on the right of the tabs where the title of the tabBox would usually appear:

enter image description here

Any suggestions on how to do this?

Here is some minimal code to work with (without the required download box):

library(shiny)
library(shinydashboard)

ui <- dashboardPage(
  dashboardHeader(title = "tabBoxes"), 
  dashboardSidebar(disable=TRUE), 
  dashboardBody(
    fluidRow(
      tabBox(
        title = 'Download Button',
        width = 12,
        tabPanel("Tab1", "Some text for tab 1"),
        tabPanel("Tab2", "Some text for tab 2")
        )
      ))
  )

server <- function(input, output) { }

shinyApp(ui, server)

Solution

  • Turns out its as simple as setting the tabBox title equal to a downloadButton!

    library(shiny)
    library(shinydashboard)
    
    ui <- dashboardPage(
      dashboardHeader(title = "tabBoxes"), 
      dashboardSidebar(disable=TRUE), 
      dashboardBody(
        fluidRow(
          tabBox(
            title = downloadButton(outputId = 'downloadData', label='Download'),
            width = 12,
            tabPanel("Tab1", "Some text for tab 1"),
            tabPanel("Tab2", "Some text for tab 2")
            )
          ))
      )
    
    server <- function(input, output) { }
    
    shinyApp(ui, server)