object of type 'closure' is not subsettable in shiny. Working on a simple RGL plotting function

你说的曾经没有我的故事 提交于 2019-12-05 20:17:36

Remember this error message, since it's very typical for shiny applications.

It almost always means, that you had a reactive value, but didn't use it with parentheses.

Concerning your code, I spotted this mistake here:

inFile <- reactive(input$file)
theFrames <- eventReactive(input$graph,read.csv(inFile$datapath,
    header = input$header)) 

plot3d(theFrames[[4]],theFrames[[5]],theFrames[[6]],xlab="x",ylab="y",zlab 
    = "z", type = "l", col = ifelse(theFrames[[20]]>0.76,"red","blue"))

You use inFile like a normal variable, but it isn't. It's a reactive value and thus has to be called with inFile(). The same goes for theFrames, which you called with theFrames[[i]], but should be called with theFrames()[[i]].

So the correct version would be

inFile <- reactive(input$file)
theFrames <- eventReactive(input$graph,read.csv(inFile()$datapath,
    header = input$header)) 

plot3d(theFrames()[[4]],theFrames()[[5]],theFrames()[[6]],xlab="x",ylab="y",zlab 
    = "z", type = "l", col = ifelse(theFrames()[[20]]>0.76,"red","blue"))

Maybe some additional info about the error message: Shiny evaluates the variables only when they are needed, so the reactive theFrames, containing the error, is executed from inside the plot3d function. That is why the error message tells you something about the error being in plot3d, even if the error lies somewhere else.

I would recommend you should look at your naming conventions. I have always seen this error when I am using variable name same as names of any function defined in packages or any function defined by me.

For example:

header = input$header
inFile = input$file

You should always restrict yourself in using these kinds of names, it will always be useful.

Thanks :)

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!