By taking a chunk of @ismirsehregal code, if you want to just screenshot the dashboardBody feature then the following code should work.
library(shiny)
library(shinyjs)
library(shinydashboard)
library(shinyscreenshot)
ui <- dashboardPage(
dashboardHeader(title = "Simple tabs"),
dashboardSidebar(
sidebarMenu(
menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard")),
menuItem("Widgets", icon = icon("th"), tabName = "widgets",
badgeLabel = "new", badgeColor = "green"),
actionButton("screenshot", "Take screenshot")
)
),
dashboardBody(
useShinyjs(),
tabItems(
tabItem(tabName = "dashboard",
h2("Dashboard tab content")
),
tabItem(tabName = "widgets",
h2("Widgets tab content")
)
)
)
)
server <- function(input, output, session) {
observeEvent(input$screenshot, {
shinyjs::addCssClass(selector = "body", class = "sidebar-collapse")
screenshot(
selector = "body > div > div > section"
)
})
}
shinyApp(ui, server)