Hi everyone,

I'm new in trying Shiny app in R and for the following question I need your 
help. I have a Random Forest model built with Caret Package on iris data set 
and then with Shiny I need a UI which I can upload a .csv file as the test set 
and give it to the trained model and then see what is the prediction on the 
test set in UI. Here is the model:

      

  
     > library(caret)
     > library(shiny)
     > data("iris")
     >model <- train(Species~., data=iris, trControl=train_control, method="nb")



and the code for ui and server


     > ui = fluidPage( 
 
     titlePanel("Prediction with Random Forest"), 
     sidebarLayout(position = "right", 
     sidebarPanel(fileInput('datafile', 'Choose CSV file', 
     accept=c('text/csv', 'text/comma-separated-values,text/plain'))), 
     mainPanel(textOutput("Pred"))), 
     textOutput(outputId = 'Pred') 

     )


     >  server = function (input,output) { 

     mydata <- reactive({ 

     inFile <- input$datafile 

      if (is.null(inFile)) 
      return(NULL) 

      tbl <- read.csv(inFile$datapath, header=input$header, sep=input$sep,  dec 
= input$dec) 

     return(tbl) 
      }) 
     pred=reactive({predict(model,tbl())}) 

    output$Pred <- renderPrint(pred()) 

    } 
    > 
   >     shinyApp(ui=ui,server=server)


so I want to read the .csv file, give it to the model and then show the class 
of the test set in UI.
Thanks for any help.

Elahe

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to