Home > Mobile >  Add button next to tabs in R Shiny tabBox
Add button next to tabs in R Shiny tabBox

Time:03-18

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)

CodePudding user response:

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)
  • Related