Download images in Shiny
Open
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 2.7k
- Forks
- 641
- PR merge metrics
- No merged PRs in 30d
Description
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!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the supplied Shiny example on Windows, focusing on downloadHandler() and plotly::save_image() with kaleido. Trace the generated Python call and compare it with the temporary path shown in the error; done means the example downloads the PNG without the unicodeescape error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- plotly, python, r
- Domain
- data-visualization
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100