Как получить результаты PCA в R блестящий - PullRequest
0 голосов
/ 06 марта 2020

разработка приложения на R блестящем, и я хочу получить результаты PCA моих введенных данных как часть приложения. Я запутался, как удалить NA из базы данных и преобразовать все данные в цифру c, а также форму и PCA данных. я приложил свой код, который я использовал для server.R и ui.R.

я запустил этот код и получил ошибку: введите описание изображения здесь что означает ошибка? код для шний:

library(factoextra)
library(dplyr)
library(tidyverse)
library(FactoMineR)
options(shiny.maxRequestSize = 20*1024^2)

shinyServer(function(input,output){

  # This reactive function will take the inputs from UI.R and use them for read.table() to read the data from the file. It returns the dataset in the form of a dataframe.
  # file$datapath -> gives the path of the file
  data <- reactive({
    file1 <- input$file
    if(is.null(file1)){return()} 
    read.csv(file=file1$datapath, sep=input$sep, header = input$header, stringsAsFactors = input$stringAsFactors)

  })
# this reactive output contains the summary of the dataset and display the summary in table format
 output$filedf <- renderTable({
   if(is.null(data())){return ()}
   input$file
 })

 # this reactive output contains the summary of the dataset and display the summary in table format
 output$sub <- renderTable({
   if(is.null(data())){return ()}
   subset(data(),select=c(CNV,Clinical,Genes))

 })
 p<-sub

 # This reactive output contains the dataset and display the dataset in table format
 output$table <- renderTable({
   if(is.null(data())){return ()}
   data()
 })
 ##pca
 output$pcasub<-renderTable({
   if(is.null(data())){return ()}

 PCA(p,scale.unit = TRUE)
 })
 # the following renderUI is used to dynamically generate the tabsets when the file is loaded. Until the file is loaded, app will not show the tabset.
 output$tb <- renderUI({
   if(is.null(data()))
     h5("PRED")
   else
     tabsetPanel(tabPanel("PCA", tableOutput("pcasub")),tabPanel("Data", tableOutput("table")),tabPanel("Summary", tableOutput("pcasub")))
 })
})

library(shiny)
shinyUI(fluidPage(
   titlePanel("File Input"),
   sidebarLayout(
       sidebarPanel(
         #  fileInput("file","Upload clinical data file"), # fileinput() function is used to get the file upload contorl option
           fileInput("file","Upload miRNA raw read count file"), # fileinput() function is used to get the file upload contorl option

           helpText("Default max. file size is 5MB"),
           tags$hr(),
           h5(helpText("Select the read.csv parameters below")),
           checkboxInput(inputId = 'header', label = 'Header', value = TRUE),
           checkboxInput(inputId = "stringAsFactors", "stringAsFactors", FALSE),
           br(),
           radioButtons(inputId = 'sep', label = 'Separator', choices = c(Comma=',',Semicolon=';',Tab='\t', Space=''), selected = ',')
       ),
       mainPanel(
           uiOutput("tb")

           # use below code if you want the tabset programming in the main panel. If so, then tabset will appear when the app loads for the first time.
           #       tabsetPanel(tabPanel("Summary", verbatimTextOutput("sum")),
           #                   tabPanel("Data", tableOutput("table")))
       )

   )
))

1 Ответ

0 голосов
/ 06 марта 2020

Я думаю, что здесь есть несколько вещей, которые могут помочь.

Во-первых, у вас может быть отдельное выражение reactive для ваших подмножественных данных. Это может использоваться / использоваться другими результатами вкладки.

Кроме того, похоже, у вас есть два идентичных tableOutput для pcasub в вашем tabsetPanel. Сделал бы каждого уникальным. Я изменил один для сводки на pcasummary.

Результаты PCA не будут кадром данных. Один простой способ показать результаты - использовать verbatimTextOutput и renderPrint. Это было применено как для pcasub, так и для pcasummary. В зависимости от того, что вам нужно, вы можете захотеть PCA() в отдельной реактивной функции или в сочетании с sub_data.

Посмотрите, ближе ли это к тому, что вам нужно.

server <- function(input,output){

  # This reactive function will take the inputs from UI.R and use them for read.table() to read the data from the file. It returns the dataset in the form of a dataframe.
  # file$datapath -> gives the path of the file
  data <- reactive({
    file1 <- input$file
    if(is.null(file1)){return()} 
    read.csv(file=file1$datapath, sep=input$sep, header = input$header, stringsAsFactors = input$stringAsFactors)
  })

  sub_data <- reactive({
    subset(data(),select=c(CNV,Clinical,Genes))
  })

  # this reactive output contains the summary of the dataset and display the summary in table format
  output$filedf <- renderTable({
    if(is.null(data())){return ()}
    input$file
  })

  # this reactive output contains the summary of the dataset and display the summary in table format
  output$sub <- renderTable({
    if(is.null(data())){return ()}
    sub_data()
  })

  # This reactive output contains the dataset and display the dataset in table format
  output$table <- renderTable({
    if(is.null(data())){return ()}
    data()
  })

  ##pca
  output$pcasub<-renderPrint({
    if(is.null(data())){return ()}
    PCA(sub_data(),scale.unit = TRUE)
  })

  ##pca summary
  output$pcasummary<-renderPrint({
    if(is.null(data())){return ()}
    summary(PCA(sub_data(),scale.unit = TRUE))
  })

  # the following renderUI is used to dynamically generate the tabsets when the file is loaded. Until the file is loaded, app will not show the tabset.
  output$tb <- renderUI({
    if(is.null(data()))
      h5("PRED")
    else
      tabsetPanel(tabPanel("PCA", verbatimTextOutput("pcasub")),tabPanel("Data", tableOutput("table")),tabPanel("Summary", verbatimTextOutput("pcasummary")))
  })
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...