0

I want to import a dataset by user and edit some cells inside the r script like change the third cell to 99, but it will show the error message: Error : cannot coerce class ""function"" to a data.frame.

server <- function(input, output) {

output$contents <- renderTable({

req(input$file1)

df <- read.csv(input$file1$datapath,
               header = input$header,
               sep = input$sep)
df[1,3]=99
df
})
output$downloadData<-downloadHandler(
filename=function(){
  paste("data",".csv",sep="")
},
content=function(file){
  write.csv(df,file)
}
)
}
Cutris
  • 1
  • 1
  • Hi, you are missing a UI, so your example is not easily reproducible. Please consider creating a [reproducible example](https://stackoverflow.com/questions/48343080/how-to-convert-a-shiny-app-consisting-of-multiple-files-into-an-easily-shareable), that makes it easier to help. – Florian Apr 25 '18 at 09:21
  • 1
    There is a function called `df` in the `stats` package - and the line `write.csv(df,file)` refers to this function rather than the dataset. The variable `df` is only available in the `renderTable` scope. – Gregor de Cillia Apr 26 '18 at 20:48

1 Answers1

0

I had a similar problem, however in my case R could not coerce class "lm" to a data.frame. I've also found on many forums that people have the same problem with other functions (lm, function, ggplot, mids, etc.). So far I saw we all did a similar mistake, we named our data frames too simply, and because of that, our data frame names were overlapping with function names and arguments names in the function, which I guess created the error. So my suggestion is to change the names of data frame and objects:

server1 <- server
input1 <- input
output1 <- output
Natalia K
  • 1
  • 1