我需要在单击按钮时将NULL设置为reactive。我想知道是否有可能将NULL设置为另一个reactive中的reactive -更准确地说,使第二个reactive返回NULL。在下面的示例中,data (作为模块参数)作为reactive从其他模块传递。
module_server <- function(id, data){
moduleServer(
id,
function(input, output, session) {
ns <- NS(id)
# 1st reactive
reactive1 <-reactive(data())
reactive1(NULL)
# more code...如您所见,我试图将NULL设置为reactive1,但它不起作用。
发布于 2021-05-01 01:43:07
是否要在满足条件时为其赋予空值?例如:
reactive1 <- reactive({
if(condition is met){
data()
} else {
return(NULL)
}发布于 2021-05-01 02:05:32
这就是Winston Chang所说的“捕捉NULL”。James的代码将会工作,但是,如果您在开始时捕捉到null,那么在不满足初始条件的情况下依赖于反应式的任何东西也将是null。例如,如果下例中的r0为null,则r1也将为null。请注意,您不必显式地将r1 (或r0)设置为null。我个人的方法是这样做:
r0<- shiny::reactive({
if(!is.null(input$blah)){
#do something here
}
})
r1<- shiny::reactive({
if(!is.null(r0())){
#do some other thing
}
})https://stackoverflow.com/questions/67337770
复制相似问题