0

I made a script to compute a statistical test with R. Everything is ok and I have my result.
Now I'd like to do it with R Shiny. The goal is to import a file with the fileInput component, then to make the statistical test and finally display it.
I tried to define both the UI part and the server part but this is not working. Indeed I have the following error :

An error has occurred. Check your logs or contact the app author for clarification

Here is my R script :

library("lsr")
library("shiny")

ui <- fluidPage(
  titlePanel("title panel"),
  fluidRow(
    column(3, fileInput("file", h3("File input"))
    )
  ),
  fluidRow(
  column(width = 3, textOutput("info"))
 )
)

server <- function(input, output) {
  output$info <- renderText({
  mycsv <- read.csv(input$file, header = TRUE, sep = ";") 
  mycsv <- subset(mycsv, V12=="Nutriment")
  df <- as.data.frame(t(mycsv))
  colnames(df) <- c("an1", "an2")
  df2 <- head (df,-2)
  cramer<-cramersV(df2$an1, df2$an2)
  res<-data.frame(cramer)
 })
}

shinyApp(ui = ui, server = server)

Edit : the dataset used is the one :

0;1;10;2;3;4;5;6;7;8;9;name;year 0;3;0;4;3;0;1;0;4;0;2;Conservatisme;2020
0;0;0;1;2;1;4;2;4;1;1;Humidité;2021
0;0;0;1;2;2;3;2;2;0;0;Nutriment;2020
0;0;0;0;2;3;4;2;2;0;0;Nutriment;2021
0;1;0;2;4;5;2;0;1;1;0;Conservatisme;2021
0;0;0;0;3;3;3;2;3;2;1;Humidité;2020

What is the problem and how could I display the result stored in the res variable ?
Any help would be very appreciated, thanks.

Julien
  • 699
  • 3
  • 14
  • 30
  • 1
    Without minimal reproducible example it's impossible to tell, but at least `subset(mycsv, V12=="Nutriment")` looks weird (is it really spelled Nutri**m**ent)? But if that is not the issue you really should provide a [minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610) and the exact error message. – dario Nov 03 '21 at 13:45
  • @dario - thanks for your answer, edit done. Yes, ```Nutriment``` is a value of a column I use to do my subset. – Julien Nov 03 '21 at 14:16

1 Answers1

1

Try this

library("lsr")
library("shiny")

ui <- fluidPage(
  titlePanel("title panel"),
  fluidRow(
    column(3, fileInput("file", h3("File input")))
  ),
  fluidRow(
    column(width = 6, DTOutput("t1"), 
           verbatimTextOutput("info")
           )
  ) 
)

server <- function(input, output) {
  
  mycsv <- reactive({
    req(input$file)
    mycsv <- read.csv(input$file$datapath, header = TRUE, sep = ",") 
    mydf <- subset(mycsv, name=="Nutriment")
    mydf
  })
  
  output$t1 <- renderDT({
    datatable(mycsv())
  })
  
  output$info <- renderPrint({

    df <- as.data.frame(tFrame(mycsv()))
    colnames(df) <- c("an1", "an2")
    df2 <- head(df,-2)
    cramer<-cramersV(df2$an1, df2$an2)
    res<-data.frame(cramer)
    res
  })
}

shinyApp(ui = ui, server = server)

output

YBS
  • 19,324
  • 2
  • 9
  • 27