0

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"
    )
1
  • It's about shinydashboard::sidebarMenu Commented Jun 16, 2022 at 13:14

2 Answers 2

1

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)
11
  • Thank you, it's working there is'nt the sidebarmenu in the screenshot but the rest of the application is cut on the left side :( Commented Jun 16, 2022 at 13:37
  • 1
    Maybe we could programmatically collapse the sidebar before taking a screenshot of the whole page. Is that an option? Commented Jun 16, 2022 at 13:43
  • 1
    Yes it is an option, but the ideal would be that users do not have to do anything to have a perfect screenshot Commented Jun 16, 2022 at 14:31
  • 1
    @Elise_351995 Please check my edited code above - the user doesn't have to do something - the sidebar is collapsed programmatically before taking the screenshot. Commented Jun 16, 2022 at 14:34
  • 2
    @ismirsehregal, was searching for hours a way to make it work, your code finally solved my issue. Thank you so much, upvote. (und schade, dass der Eröffner nicht mal Rückmeldung gibt... Danke nochmals!)
    – Marco_CH
    Commented Nov 22, 2022 at 13:21
0

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)

Not the answer you're looking for? Browse other questions tagged or ask your own question.