Shiny Screenshot without the side bar menu

266 views Asked by At

Do you know if it's possible to screenshot all my shiny app without the side bar menu ?

I've tried "selector = #nameofmytabItem" but it don't success.

Here is my actual code :

observeEvent(input$screenshot, {
    screenshot(
      selector = "#Radar_Moyennes2"
    )
2

There are 2 answers

11
ismirsehregal On

Please check the following:

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)
0
Daniel F. On

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)