单击按钮时将 NULL 设置为反应式
Setting NULL to reactive when button is clicked
我需要在单击按钮时将 NULL 设置为 reactive
。在我下面的示例中,'data'(作为模块参数)作为响应从其他模块传递。现在,我想单击按钮并将 NULL 设置为 reactiveExpr
。我在这里做的方式是行不通的。我不需要在任何条件下将 NULL 设置为 reactive
,只需单击按钮即可。
mod_ui <- function(id){
ns <- NS(id)
actionButton(ns("btn"), "Click me")
}
mod_server <- function(id, data){
moduleServer( id, function(input, output, session) {
ns <- NS(id)
reactiveExpr <- reactive(data())
observeEvent(input$btn, {
reactiveExpr(NULL)
})
# some more code...
我该怎么做?
不使用电抗导体 (reactive
),而是使用电抗值:
reactiveExpr <- reactiveVal()
observe({
reactiveExpr(data())
})
observeEvent(input$btn, {
reactiveExpr(NULL)
})
我需要在单击按钮时将 NULL 设置为 reactive
。在我下面的示例中,'data'(作为模块参数)作为响应从其他模块传递。现在,我想单击按钮并将 NULL 设置为 reactiveExpr
。我在这里做的方式是行不通的。我不需要在任何条件下将 NULL 设置为 reactive
,只需单击按钮即可。
mod_ui <- function(id){
ns <- NS(id)
actionButton(ns("btn"), "Click me")
}
mod_server <- function(id, data){
moduleServer( id, function(input, output, session) {
ns <- NS(id)
reactiveExpr <- reactive(data())
observeEvent(input$btn, {
reactiveExpr(NULL)
})
# some more code...
我该怎么做?
不使用电抗导体 (reactive
),而是使用电抗值:
reactiveExpr <- reactiveVal()
observe({
reactiveExpr(data())
})
observeEvent(input$btn, {
reactiveExpr(NULL)
})