Remove trigger dependency from renderTable

shiny

#1

Hi everyone,

I am having a shiny app like below. In here, renderTable depend on two reactive values, 'mydata' and 'input$unrelated_option'. However, 'mydata' is the only one that I would like to have. In this case, the renderTable gets reevaulated everytime a user changes the 'input$unrelated_option', even though 'mydata' remains the same, and this is not the behavior that I wanted. So, I am wondering, is there a way for me to remove the trigger dependency of 'input$unrelated_option' from this piece of code?

Thank you!

mydata = reactive({
	# some reactive value here
}) 
output$myoutput = renderTable(
{
	process_data = function(mydata){
		if(input$unrelated_option == "A"){ # unrelated_option is a select input with "A", "B", "C"
			# do something here
		}
	}	
	return(process_data(mydata()))
}
)

#2

Hi @trcc

isolate() is the function you are looking for. Link: https://shiny.rstudio.com/reference/shiny/1.1.0/isolate.html

Create a non-reactive scope for an expression

Update your if statement to be:

if (isolate(input$unrelated_option) == "A") {
  # ...
}

This change will cause input$unrelated_option to be read only, and never trigger reactivity (when used within an isolate call).

Hope this helps!

Best,
Barret