shiny screenshot appears with colorless legend

76 views Asked by At

In shiny the ggplotly visual looks like:

enter image description here

If I create a screenshot with shinyscreenshot it appears with a colorless legend:

enter image description here

Is there any way to solve this issue?


Update 12:04

It seems that this issues only appears with colorbars. With factorized groups the legend works:

enter image description here

Unfortunately, in real world data I need the colorbar as its a range between 0.0001 and 100%.


MWE

library(shiny)
library(shinydashboard)
library(shinyscreenshot)
library(data.table)
library(DT)
library(bslib)
library(plotly)

################################################################################
################################ S E R V E R ###################################
################################################################################

server = shinyServer(function(input,output){
  
  output$histogram = renderPlotly(
    ggplotly(ggplot(mtcars, aes(x=disp, y=hp, color=gear)) + geom_point())
  )
  
  
  output$active_cases = DT::renderDataTable(
    mtcars)
  
  ######################### SCREENSHOT REACTIVE FUNCTION #########################  
  observeEvent(input$go,{
    screenshot(id = "to_plot") # plot only ID "to_plot"
  })
  ######################### SCREENSHOT REACTIVE FUNCTION #########################
  
})


################################################################################
#################################### U I #######################################
################################################################################

ui = shinyUI(
  dashboardPage(
    dashboardHeader(
      title="just a test"
    ),
    dashboardSidebar(
      sidebarMenu(id="tabs",
                  menuItem("Tab1", tabName="active_cases", icon = icon("magnifying-glass-location"))
      )
    ),
    dashboardBody(
      tabItems(
        tabItem(tabName="active_cases", shiny::h2("Active Cases"),
          fluidRow(actionButton("go", "go")),
              fluidRow(
                box(title="Table", status="primary", solidHeader=TRUE, div(DT::dataTableOutput("active_cases")))
              ),
          div(id="to_plot",
              fluidRow(
                box(title="Visual1", status="primary", solidHeader=TRUE, plotlyOutput("histogram"))
              )
          )
)))))


################################################################################
################################### R U N ######################################
################################################################################

shinyApp(ui, server)
1

There are 1 answers

2
ismirsehregal On BEST ANSWER

You could use library(capture) instead of library(shinyscreenshot):

# remotes::install_github("dreamRs/capture")

library(shiny)
library(shinydashboard)
library(capture)
library(data.table)
library(DT)
library(bslib)
library(plotly)

################################################################################
################################ S E R V E R ###################################
################################################################################

server = shinyServer(function(input,output){
  
  output$histogram = renderPlotly(
    ggplotly(ggplot(mtcars, aes(x=disp, y=hp, color=gear)) + geom_point())
  )
  
  
  output$active_cases = DT::renderDataTable(
    mtcars)
})


################################################################################
#################################### U I #######################################
################################################################################

ui = shinyUI(
  dashboardPage(
    dashboardHeader(
      title="just a test"
    ),
    dashboardSidebar(
      sidebarMenu(id="tabs",
                  menuItem("Tab1", tabName="active_cases", icon = icon("magnifying-glass-location"))
      )
    ),
    dashboardBody(
      tabItems(
        tabItem(tabName="active_cases", shiny::h2("Active Cases"),
                fluidRow(
                  capture::capture(
                    selector = "#to_plot",
                    filename = "capture_plotly.png",
                    icon("camera"), "Capture plotly graph",
                    options=list(backgroundColor = "white")
                  )
                ),
                fluidRow(
                  box(title="Table", status="primary", solidHeader=TRUE, div(DT::dataTableOutput("active_cases")))
                ),
                div(id="to_plot",
                    fluidRow(
                      box(title="Visual1", status="primary", solidHeader=TRUE, plotlyOutput("histogram"))
                    )
                )
        )))))


################################################################################
################################### R U N ######################################
################################################################################

shinyApp(ui, server)