【问题标题】:shiny screenshot appears with colorless legend闪亮的屏幕截图出现无色图例
【发布时间】:2022-11-17 17:54:24
【问题描述】:

在闪亮的 ggplotly 视觉效果中看起来像:

如果我使用 shinyscreenshot 创建屏幕截图,它会显示无色图例:

有什么办法可以解决这个问题吗?


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)

【问题讨论】:

    标签: r shiny shinyscreenshot


    【解决方案1】:

    您可以使用 library(capture) 而不是 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)
    

    【讨论】:

    • 非常感谢。好的,如果有shinyscreenshot 的解决方案,我会等待,否则我会接受这个答案。如果可能的话,我更愿意坚持shinyscreenshot,因为我无法在我们闪亮的服务器上安装和保留包,但如果没有其他方法,那么我会找到capture的解决方案
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-05
    • 2012-05-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多