我刚刚发现了闪亮的强大之美。我尝试制作一个简单的应用程序,我可以使用rcmdr中的FactoMineR插件加载excel文件并在其上执行PCA(现在,代码只是针对此特定文件编写的)。
我设法建立一个应用程序,我可以加载我的文件,并显示三个不同的情节与PCA的结果。在RStudio中一切正常,但是当我部署应用程序时,图表不会显示。其他一切似乎工作正常!
有关该问题可能来自哪里的任何想法?
最佳标志,
Léolo
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)