Help with shiny multi class classification

i am working on my academic project and facing some errors in shiny. i am doing multi class classification using UBL package and followed by random forest algo.
i am stuck in over class classification (using UBL package) on line number 166 to 179, geeting error saying that incorrect number of dimensions . i tried and modified the code but didn't work.
please help me to solve this error.
thank you.

i am attaching my entire code and two files, file1 and file 2 for input.

library(shiny)


ui <-fluidPage(
    
    sidebarLayout(
        sidebarPanel(
            
            fileInput("file","Upload FIle_1"), # fileinput() function is used to get the file upload contorl option
            fileInput("filecli","Upload FILE_2"), # fileinput() function is used to get the file upload contorl option
            helpText("Default max. file size is 30MB"),
            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")
            
            
        )
        
    )
)

#server <-       
options(shiny.maxRequestSize=30*1024^2)

server <- function(input,output){
    
    library(shiny)
    library(factoextra)
    library(dplyr)
    library(tidyverse)
    library(FactoMineR)
    library(tidyr)
    library(caret)
    library(scorecard)
    library(curl)
    library(imputeTS)
    library(UBL)#multiple class classification 
    
    #reading mirna data and printing in str form instead of entire data set
    datami <- reactive({
        file1 <- input$file
        if(is.null(file1)){return()}
        read.csv(file=file1$datapath, sep=input$sep, header = input$header, stringsAsFactors = input$stringAsFactors)
    })
    
    
    output$table <- renderPrint({
        if(is.null(datami())){return ()}
        str(datami())
    })
    
    
    datami2<-reactive({
        datami2<-datami()
    })
    output$table2<-renderTable({
        datami2()
    })
    #reading clinical data
    datacli <- reactive({
        file2 <- input$filecli
        if(is.null(file2)){return()}
        read.csv(file=file2$datapath, sep=input$sep, header = input$header, stringsAsFactors = input$stringAsFactors)
    })
    
    
    #removing multiple values from data set
    removing_copy<-reactive({
        datacli() %>% distinct(submitter_id,.keep_all = TRUE)
        
    })
    output$tablecli<-renderPrint({
        str(removing_copy())
    })
    
    
    
    
    #subsetting midata
    sub_datami <- reactive({
        subset(datami(),select=c(A,B,C,Gender))
    })
    output$sub_datami1<-renderTable({
        sub_datami()
    })
    
    
    #subsetting clinical data
    sub_datacli<-reactive({
        subset(removing_copy(),select=c(age_at_index,tumor_stage))
    })
    output$sub_datacli1<-renderTable({
        sub_datacli()
    })
    
    
    #merging two data set
    merge_cli_mi<-reactive({
        cbind(sub_datami(),sub_datacli())    
        
    })
    
    output$merge_cli_mi1<-renderTable({
        #as.numeric(levels())[merge_cli_mi()]
        merge_cli_mi() })
    
    
    
    numeric_con<-reactive({
        local_cli <- merge_cli_mi()
        
        local_cli$tumor_stage <- factor(local_cli$tumor_stage,
                                        levels = c( "not reported","stage i", "stage ia","stage ib","stage ii", "stage iia","stage iib" ,"stage iii" ,"stage iiia" ,"stage iiib","stage iv" ),
                                        labels = c(1:11)
        )                                               
        local_cli        
    })
    
    
    
    
    numeric_con2<-reactive({
        local_cli2 <- numeric_con()
        
        local_cli2$Gender <- factor(local_cli2$Gender,
                                    levels = c("Female","Male"),
                                    labels = c(1,2))                                               
        local_cli2       
    })
    
    output$num2<-renderPrint({
        
        str(numeric_con2())
        
    })
    
    
    mergemi2 <-reactive({ lapply(numeric_con2(),as.numeric)
    })
    output$mergemi3 <-renderTable({
        mergemi2()
    })
    
    
    new1<-reactive({
        local_cli3<-mergemi2()
        
        local_cli3$age_at_index[which(is.na( local_cli3$age_at_index))]<-mean( local_cli3$age_at_index,na.rm=TRUE)
        
        local_cli3
    })
    output$new<-renderPrint({
        str(new1())
    })
    
    
    
    
    #oversampling using UBL package 
    rov <- reactive({
        new1()
    })
    rob <- reactive({
        
        RandOverClassif(tumor_stage ~ ., rov(), C.perc = "balance")
        
        
    })
    output$resampled_dt <- renderDataTable({
        rob()
    })
    
    
    
    
    # Data Partition using scorecard library
    
    
    ##pca
    output$pcasubmi<-renderPrint({
        if(is.null(datami())){return ()}
        PCA(new1(),scale.unit = TRUE)
    })
    
    ##pca summary
    output$pcasummary<-renderPrint({
        if(is.null(datami())){return ()}
        summary(PCA(new1(),scale.unit = TRUE))
    })
    
    
    output$pcasubmi1<-renderPlot({
        if(is.null(datami())){return ()}
        PCA(new1(),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(datami()))
            h4(style="color:red",br(),"Under Development")
        
        
        else
            
            navbarPage("Menu",
                       tabPanel("Data",
                                tabsetPanel(
                                    tabPanel("RAw Data",div(h5(" Uploaded Data file_1",style="color:red")),verbatimTextOutput("table"),div(h5(" Uploaded Data file_2",style="color:blue")),verbatimTextOutput("tablecli"))
                                )),
                       tabPanel("PCA",
                                tabsetPanel(
                                    tabPanel("PCA Result",verbatimTextOutput("pcasubmi"),verbatimTextOutput("pcasummary")),
                                    tabPanel("Graph",imageOutput("pcasubmi1"),downloadButton('downloadData', 'Download')))),
                       tabPanel("SMOTE",
                                tabsetPanel(
                                    tabPanel("Result",tableOutput("resampled_dt"))
                                ))
            )      
        
    })
    
    
    
}
# Run the application 
shinyApp(ui = ui, server = server)

file 1<-

Gender Exp A B Bio   C Slides
 Female   5 5 7  22 567      4
 Female   7 7 7  21 565      3
  Male   5 5 8  21 565      3
 Female   5 5 7  21 562      3
 Female   8 5 7  21 561      3
   Male   5 5 7  20 560      2

file2<-

submitter_id age_at_index days_to_death tumor_stage
AD-55-8087           59            --    stage ib
AD-55-8087           59            --    stage ib
AD-55-7284           74           243   stage iib
AD-55-7284           74           243   stage iib
AD-75-7031           --            --    stage ib
AD-75-7031           --            --    stage ib
AD-55-8205           76            --   stage iia
AD-55-8205           76            --   stage iia
AD-86-8281           75            --    stage ia
AD-86-8281           75            --    stage ia
AD-05-4432           66            --   stage iib
AD-05-4432           66            --   stage iib

its not a dataframe but rather a list...
do

 rov <- reactive({
 as.data.frame(new1())
 })
1 Like

thank you very much ..
as i mentioned i am implementing random forest method.
after solving this error i have divided data in test and training set using scorecard library , i tried to use random forest method following code but got error saying that

non-numeric argument to binary operator

why i am getting this error?

    
    dt_list <- reactive({
        split_df(rob(), ratio = 0.80, seed = 123)
    })
    output$dtl<-renderPrint({
        dt_list()
    })
    
    dttrain<-reactive({
        dtrs<-dt_list()
        dtrs$train
    })
   
    dtnew<-reactive({
        dttrain()
    })
  
    
    dttest<-reactive({
        dtrs<-dt_list()
        dtrs$test
    })
    
    
    #random forest implimentation

  

  
 training <-reactive({ 
      randomForest(tumor_stage~., data = dtnew())
  })
  predictig<-reactive({
      predict(training, dttest(), dttest$tumor_stage)
      
  })
  output$confusmat<-renderPrint({
    as.numeric((confusionMatrix(predictig(),training())))
      })

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.