Skip to content
This repository was 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

@ttzhou

Description

@ttzhou
  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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions