plotly / plotly/plotly.R

Download images in Shiny

未关闭
#2,141 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
R
星标
2.7k
派生
641
PR 合并指标
30 天内没有已合并 PR

描述

Hi! I'm using plotly in a shiny. When I want to download the image, first I used export, it works, but it returns a message "use orca", but it was also superseded by kaleido(). So I use save_image(), and it return an error .

Warning: Error in py_run_string_impl:   File "<string>", line 1
    open('C:\Users\limbo\AppData\Local\Temp\RtmpkD8Zlu\file1d5837d66529.png', 'wb').write(scope_1d58780818d2.transform(sys.modules['json'].loads(scope_1d58780818d2._last_plot), format='png', width=None, height=None, scale=None))
                                                                            ^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

  [No stack trace available]

my shiny

library(shiny)
library(plotly)

ui <- fluidPage(
  plotlyOutput("plot"),
  downloadButton("download", "Download")
)

server <- function(input, output, session) {
  p <- reactive({
    
    a <- ggplot(iris, 
                aes(x = Species, 
                    y = Sepal.Length)
                ) + 
      geom_boxplot() + 
      theme_bw()
    a <- ggplotly(a)
    a
  })

  
  output$plot <- renderPlotly(p())
  
  output$download <- downloadHandler(
    filename = function(){
      paste0(paste0("test", 
                    Sys.Date()), 
             ".png")
    },
    
    content = function(file){
      plotly::save_image(p(), file = file)
    }
  )
}

shinyApp(ui, server)

What can I do about that? Thanks!

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先在 Windows 上运行所提供的 Shiny 示例,重点检查使用 kaleido 的 downloadHandler() 和 plotly::save_image()。跟踪生成的 Python 调用,并将其与错误中显示的临时路径进行比较;完成标准是示例能够在不出现 unicodeescape 错误的情况下下载 PNG。

由索引模型根据 Issue 内容生成。

评估

技术栈
plotly, python, r
领域
data-visualization
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。