You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi @swsoyee ,
I have been trying to export the image generated through m_png() through a download button in Shiny, but I am not able to get that work. I have tried png-dev.off(), png::writePNG and also htmlWidgets-webshot but none of them worked for me. They work normally in an R environment but not in a shiny app download button. Here is the corresponding code from the server section of my app.R:
expression <- {
r3dmol( viewer_spec = m_viewer_spec(cartoonQuality = 10, lowerZoomLimit = 50, upperZoomLimit = 350) ) %>%
# Add model to scene
m_add_model(data = pdb_file, format = "pdb") %>%
# Zoom to encompass the whole scene
m_zoom_to() %>%
# Set style of structures
m_set_style(style = m_style_cartoon(color = "#00cc96")) %>%
# Set style of specific selection (selecting by secondary)
m_set_style( sel = m_sel(ss = "s"), style = m_style_cartoon(color = "#636efa", arrows = TRUE) ) %>%
# Style the alpha helix
m_set_style( sel = m_sel(ss = "h"), style = m_style_cartoon(color = "#ff7f0e") )
}
output$pdb <- renderR3dmol(expression)
data2 <- reactiveValues()
data2$imageToSave <- renderImage({
expression %>% m_png()
})
output$downloadImage <- downloadHandler(
filename = "AuxPhosImage.png",
content = function(file){
png::writePNG(data2$imageToSave)
}
)
I am using 'pdb' and 'downloadImage' in the 'ui' part as fluidRow(column(6, align="center", downloadButton('downloadImage','Download Image'), r3dmolOutput("pdb")).
I tried the same procedure for to save a ggplot object using ggsave which worked perfectly. But I am not able to get this working. One difference that I found is that this png from r3dmol is rendered into the 'viewer' but not the 'plot' section, for which the reason the png saving options are not working I guess, I might be wrong.
Any help is highly appreciated.
Thanks, Sumanth.
The text was updated successfully, but these errors were encountered:
I found is that this png from r3dmol is rendered into the 'viewer' but not the 'plot' section
@sumanthmutte Yes, actually the m_png() function do not create a image, it just convert the widget to a base64 png.
The easiest way to do this is to write a help text that reminds the user that they can right-click to save the results of m_png()
Hi @swsoyee ,
I have been trying to export the image generated through m_png() through a download button in Shiny, but I am not able to get that work. I have tried png-dev.off(), png::writePNG and also htmlWidgets-webshot but none of them worked for me. They work normally in an R environment but not in a shiny app download button. Here is the corresponding code from the
server
section of my app.R:I am using 'pdb' and 'downloadImage' in the 'ui' part as
fluidRow(column(6, align="center", downloadButton('downloadImage','Download Image'), r3dmolOutput("pdb"))
.I tried the same procedure for to save a ggplot object using ggsave which worked perfectly. But I am not able to get this working. One difference that I found is that this png from r3dmol is rendered into the 'viewer' but not the 'plot' section, for which the reason the png saving options are not working I guess, I might be wrong.
Any help is highly appreciated.
Thanks, Sumanth.
The text was updated successfully, but these errors were encountered: