How can I set NULL to reactive?

Hi, I need to set NULL to reactive when a button is clicked. In my example below 'data' (as module parameter) is passed as reactive from other module. Now, I want to click button and set NULL to reactiveExpr . The way I'm doing it here is not working. I don't need set NULL to reactive base on any condition, just by clicking the button.

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, {

# some more code...

How can I do this?

Look into the use of reactiveValue

I know, I use it in some other cases but here I need reactive

Do you want the 0bject to contain data at first and then clear from button press and never again ? Or is there supposed to be some condition to refill?.

In general to do one or another thing based on conditions if-else logic can be used.

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({
      switchvar <- as.numeric(input$btn) %% 2
      ) })

    output$modtable <- renderTable({

ui <- fluidPage(

server <- function(input, output, session) {

shinyApp(ui, server)

Thank you for your answer:)

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.