Shiny - destroying all observers within a function

Hi there,

Perhaps someone has experience with destroying observers in Shiny.

Say for example you have the following function:

# example.R
serverLogic <- function(input, output, session){
  observeEvent(input$example, {
     print('some server side code here')
  })
}

Is it then possible to destroy all observers inside the serverLogic function without having to assign these observeEvents to a variable? I would like to prevent having to assign observeEvents to say a variable x and then having to run x$destroy().

The reason behind asking this is that it would become possible to have a 'hot reload' mechanism for server type functions. If you do not destroy the observers within a function you will unfortunately introduce duplicates which causes unintended effects.

Happy to exchange thoughts,

Michael

Hi Michael,

Destroying observers has always been like the pita bun around my shoarma meat (speaking of a 'hot reload'). In real life, and in coding life. With pita I obviously refer to PITA, also known as Pain in the Ass or Bread dans le Cul as the French say.

Back to your question. In order to prevent duplicates from being formed it's generically advised to modify the string in the print() function. Please try print('I don't want any side effects :rage:') and try again.

Regards,

Paul

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