Графики не отображаются при развертывании блестящего приложения
Я только что обнаружил мощную красоту Shiny. Я попытался создать простое приложение, в котором я могу загрузить файл Excel и выполнить на нем PCA, используя плагин FactoMineR в rcmdr (на данный момент код написан только для этого конкретного файла).
Мне удается создать приложение, в которое я могу загрузить свой файл, и отобразить три разных графика с результатами PCA. В RStudio все работает нормально, но при развертывании приложения график не отображается. Все остальное вроде работает нормально!
Есть идеи, откуда эта проблема?
С наилучшими пожеланиями,
Leolo
library(shiny)
library(gdata)
library(Rcmdr)
library(RcmdrMisc)
library(FactoMineR)
options(shiny.sanitize.errors = FALSE)
# Define UI ----
ui <- fluidPage(
titlePanel("Introducing PCApp"),
p("Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Nam augue enim, vestibulum vitae nisi vel, placerat suscipit ipsum.
Duis eu quam lobortis, tincidunt tellus eget, condimentum est.
In nibh velit, tempor ac neque et, viverra pretium sapien.
Fusce massa sapien, varius eu rutrum at, pharetra sit amet leo. Orci varius.",
br(),
sidebarLayout(position = "left",
sidebarPanel(position = "left",
p("Principal Composant Analysis of PCR data from normal and tumor samples.",
br(), br(), "Add your data by importing a valid file.", br(),
span(a("What's a valid file?", target="popup", onclick="window.open('validfile.html','popup','width=505,height=600'); return false;"))),
fileInput("means", "Choose a valid file",
accept = c(
"text/csv",
"text/comma-separated-values,text/plain",
".csv",
".xls",
".xlsx")
),
tags$hr(),
selectInput("var",
label = "Choose a variable to display",
choices = c("Factor Map", "Variables Factor map (PCA)",
"Individuals Factor map (PCA)"),
selected = "Factor Map")
),
mainPanel(
plotOutput("means"),
textOutput("selected_var")
)
)
)
# Define server logic ----
server <- function(input, output) {
output$means <- renderPlot({
# input$file1 will be NULL initially. After the user selects
# and uploads a file, it will be a data frame with 'name',
# 'size', 'type', and 'datapath' columns. The 'datapath'
# column will contain the local filenames where the data can
# be found.
inFile <- input$means
if (is.null(inFile))
return(NULL)
means<-readXL(inFile$datapath,
rownames=TRUE, header=TRUE, na="",
stringsAsFactors=TRUE)
means.PCA<-means[, c("CTNNB1", "LIN28B", "MYC", "SMARCA4", "SOX9", "TERT",
"TP53", "hsa.let.7b")]
res<-PCA(means.PCA , scale.unit=TRUE, ncp=2, graph = FALSE)
res.hcpc<-HCPC(res ,nb.clust=-1,consol=FALSE,min=3,max=10,graph=FALSE)
if(input$var == "Factor Map")
p<-res.hcpc<-HCPC(res ,nb.clust=-1,consol=FALSE,min=3,max=10,graph=TRUE)
print(p)
if(input$var == "Individuals Factor map (PCA)")
p<-plot.PCA(res, axes=c(1, 2), choix="ind", habillage="none", col.ind="black",
col.ind.sup="blue", col.quali="magenta", label=c("ind", "ind.sup", "quali"),
new.plot=TRUE)
print(p)
if(input$var == "Variables Factor map (PCA)")
p<-plot.PCA(res, axes=c(1, 2), choix="var", new.plot=TRUE, col.var="black",
col.quanti.sup="blue", label=c("var", "quanti.sup"), lim.cos2.var=0)
summary(res, nb.dec = 3, nbelements=10, nbind = 10, ncp = 3, file="")
remove(means.PCA)
print(p)
})
output$selected_var <- renderText({
inFile <- input$means
if (is.null(inFile))
return(paste("Please load a valid file ..."))
paste("You have selected : ", input$var)
})
}
# Run the app ----
shinyApp(ui = ui, server = server)