gpt4 book ai didi

r - 'closure' 类型的对象在 shiny 中不可子集化。使用简单的 RGL 绘图函数

转载 作者:行者123 更新时间:2023-12-01 11:24:49 28 4
gpt4 key购买 nike

我正在用 rglshinyRGL 包编写 Shiny 的代码,试图通过让用户插入 csv 来绘制 3D 线图特定格式的文件。但是对象类型关闭错误不断出现。好像是因为它找不到函数plot3d,或者我可能是错的。

代码如下:

用户界面

library(shiny)
library(rgl)
library(shinyRGL)

# Define UI for application that draws a histogram
shinyUI(fluidPage(
titlePanel("title panel"),

sidebarLayout(
sidebarPanel(
helpText("Please select a CSV file with the correct format."),
tags$hr(),
fileInput("file","Choose file to upload",accept = c(
'text/csv',
'text/comma-separated-values',
'text/tab-separated-values',
'text/plain',
'.csv',
'.tsv',
label = h3("File input"))
),
tags$hr(),
checkboxInput('header', 'Header', TRUE),

actionButton("graph","PLOT!")
),


mainPanel(textOutput("text1"),
webGLOutput("Aplot")))
)
)

服务器

library(shiny)
library(rgl)
library(shinyRGL)

options(shiny.maxRequestSize = 9*1024^2)
shinyServer(
function(input, output) {


output$text1 <- renderText({
paste("You have selected", input$select)
})
output$"Aplot" <- renderWebGL({
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"))
})
})

错误

Warning: package hinyRGL?was built under R version 3.3.1 Warning: Error in [[: object of type 'closure' is not subsettable Stack trace (innermost first): 70: plot3d 69: func [C:\Users\Ian\workspace\Copy of Leap SDK/Test\App_1/server.R#19] 68: output$Aplot 1: runApp

最佳答案

记住这个错误消息,因为它对于 Shiny 的应用程序来说非常典型。

它几乎总是意味着,您有一个 react 值,但没有将其与括号一起使用。

关于您的代码,我在这里发现了这个错误:

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"))

您像普通变量一样使用inFile,但事实并非如此。它是一个 react 值,因此必须使用 inFile() 调用。 theFrames 也是如此,你用 theFrames[[i]] 调用它,但应该用 theFrames()[[i]] 调用>.

所以正确的版本应该是

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"))

也许关于错误消息的一些附加信息:Shiny 仅在需要时才评估变量,因此包含错误的响应式(Reactive) theFrames 是从 plot3d 内部执行的> 功能。这就是为什么错误消息会告诉您一些有关 plot3d 中的错误的信息,即使错误位于其他地方也是如此。

关于r - 'closure' 类型的对象在 shiny 中不可子集化。使用简单的 RGL 绘图函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38364783/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com