selection1
is a reactive
功能。在 Shiny 中,这意味着它是一个保存/缓存数据的函数。当您调用该函数并且其输入发生变化时,它保存的数据就会更新。如果调用它时输入没有更改,它将返回缓存的数据。
要访问数据,您需要使用调用函数本身selection1()
,然后使用常用的函数/代码来对数据进行子集化。所以在你的情况下会是
selection2 <- length(unique(selection1()$COLUMN))
当您尝试执行以下操作时,您看到的错误是标准错误$
对函数进行操作,而不使用调用该函数()
foo <- function(){
bar = data.frame(bar = c(1,2,3))
}
foo$bar
Error in foo$bar : object of type 'closure' is not subsettable
foo()$bar
[1] 1 2 3
如果您想深入了解结构的实际细节reactive
对象,只需调用str
看看它
foo <- reactive()
str(foo)
function ()
- attr(*, "observable")=Classes 'Observable', 'R6' <Observable>
Public:
.dependents: environment
.domain: NULL
.error: FALSE
.execCount: 0
.func: function (...)
.invalidated: TRUE
.label: foo
.mostRecentCtxId:
.running: FALSE
.updateValue: function ()
.value: NULL
.visible:
clone: function (deep = FALSE)
getValue: function ()
initialize: function (func, label = deparse(substitute(func)), domain = getDefaultReactiveDomain(),
self: Observable, R6
- attr(*, "class")= chr "reactive"