muna59
June 16, 2021, 4:50pm
1
Hi,
I am developing a shiny app to analyze data using several mixOmics functions (plotIndiv, plotVar, plotLoadings). When I download the figures from the app, I am getting .htm files instead of the figures that are supposed to be png or pdf format. I noticed this issue with figures from mixOmics only. The other figures in the app from other libraries are downloaded successfully.
Thank you
Hi @muna59 ,
I have no issue downloading the plot as png. Here’s the app that I use:
library(shiny)
library(mixOmics)
# Define UI for application that draws a histogram
ui <- fluidPage(
titlePanel("plotIndiv"),
sidebarLayout(
sidebarPanel(
numericInput('pc1', 'First PC', value=1,
min=1, max=5, step=1),
numericInput('pc2', 'Second PC', value=2,
min=1, max=5, step=1)
),
mainPanel(plotOutput("plotIndiv"))
)
)
server <- function(input, output) {
output$plotIndiv <- renderPlot({
data(multidrug)
comp <- c(input$pc1, input$pc2)
pca.res <- pca(multidrug$ABC.trans, ncomp = 5, scale = TRUE)
# biplot(pca.res, group = multidrug$cell.line$Class, legend.title = 'Class')
# samples representation
plotIndiv(pca.res, comp = comp, ind.names = multidrug$cell.line$Class,
group = as.numeric(as.factor(multidrug$cell.line$Class)))
})
}
# Run the application
shinyApp(ui = ui, server = server)
I click on ‘Open in Browser’ and then I download it. Can you confirm you have any issues doing so with the app I provided?
Best,
Al
muna59
June 17, 2021, 1:59pm
3
Thank you.
Actually, I need to download the plot in pdf format. For example, I tried to use the following code:
library(shiny)
library(mixOmics)
# Define UI for application that draws a histogram
ui <- fluidPage(
titlePanel("plotIndiv"),
sidebarLayout(
sidebarPanel(
numericInput('pc1', 'First PC', value=1,
min=1, max=5, step=1),
numericInput('pc2', 'Second PC', value=2,
min=1, max=5, step=1),
downloadButton("Indiv_pdf", "Save as pdf")
),
mainPanel(plotOutput("plotIndiv"))
)
)
server <- function(input, output) {
output$plotIndiv <- renderPlot({
data(multidrug)
comp <- c(input$pc1, input$pc2)
pca.res <- pca(multidrug$ABC.trans, ncomp = 5, scale = TRUE)
# biplot(pca.res, group = multidrug$cell.line$Class, legend.title = 'Class')
# samples representation
plotIndiv(pca.res, comp = comp, ind.names = multidrug$cell.line$Class,
group = as.numeric(as.factor(multidrug$cell.line$Class)))
})
output$Indiv_pdf <- downloadHandler(
filename = function() {base::paste("pls_ind", ".pdf", sep = '')},
content = function(file){
ggsave(file, plot = plotIndiv, device = 'pdf')
}
)
}
# Run the application
shinyApp(ui = ui, server = server)
It gives the following error: “Couldn’t download _ Server problem”.
Hi @muna59 ,
Please note that this is a Shiny support question and not a mixOmics one. Feel free to check online Shiny forums to get assistance (e.g. Problem in downloading the plot with downloadhandler for shiny app - shiny - RStudio Community ).
Best,
Al