Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

Odd behaviour with add_tooltip if a ggvis is bound reactively #479

Open
ttzhou opened this issue Jun 27, 2018 · 0 comments
Open

Odd behaviour with add_tooltip if a ggvis is bound reactively #479

ttzhou opened this issue Jun 27, 2018 · 0 comments

Comments

@ttzhou
Copy link

ttzhou commented Jun 27, 2018

  1. Run the following
library(tidyverse)
library(shiny)
library(ggvis)

server <- function(input, output, session) {
	
	vis_data <- reactive({
		mtcars
	})
	
	output$vis <- renderUI({
		ggvisOutput('vis_test')
	})
	
	observeEvent(input$slider, {
		reactive({
			vis_data()[seq(1, input$slider), ] %>%
			ggvis(
				x = ~wt,
				y = ~mpg
			) %>%
			layer_points() %>%
			layer_bars() %>%
			add_tooltip(
				function(x) print(nrow(vis_data()[seq(1, input$slider), ]))
			)
		}) %>% bind_shiny('vis_test')
	})
		
}

ui <- function(input, output, session) { 
	fluidPage(
		sliderInput('slider', min = 1, max = nrow(mtcars), value = 3, label = 'sliderlabel'),
		htmlOutput(outputId = 'vis')	
	)
}

shinyApp(ui = ui, server = server)
  1. Hover over one of the bars, note the console/printed output. Should only print once
  2. Change the slider, hover over a bar. Now it prints twice!
  3. Change the slider again. Hover over a bar. Now it prints three times!

My hunch is that every time bind_shiny is called, the observer for add_tooltip isn't being destroyed, and each of these is observers is being called when the hover occurs.

Is there any workaround?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant