Reputation: 113
I'm creating a ggvis scatterplot using shiny. I'm having issues with the tooltip function. When I hover over the scatter plot, half my points on the scatterplot disappears. I can then see the tooltip information for the remaining half.
Anyone have the same issues? To reproduce the error, you can download the code and source files from:
https://github.com/er3kim78/Shiny
Server File:
library(ggvis)
library(ggplot2)
library(dplyr)
#set working directory
setwd("C:/Users/EK/Desktop/Files/R Scripts/Shiny VRC")
# read the data
vrc<- read.csv("Data File Example.csv", header = TRUE, sep=",")
str(vrc)
vrc$Impr<-as.numeric(vrc$Impr)
str(vrc)
shinyServer(
function(input, output) {
main_plot <- reactive({
xvar<-switch(input$xvar,
"Clicks" = vrc$Clicks,
"Cost" = vrc$Cost,
"Impr" = vrc$Impr)
yvar<-switch(input$yvar,
"Clicks" = vrc$Clicks,
"Cost" = vrc$Cost,
"Impr" = vrc$Impr)
vrc%>%
ggvis(~xvar, ~yvar, opacity:=0.4, key:=~Keyword) %>%
layer_points() %>%
# layer_text(text:=as.character(vrc$Account)) %>%
add_tooltip(function(vrc){paste0("Keyword: ", vrc$Keyword,"<br>xvar: ",vrc$xvar,
"<br>yvar:", vrc$yvar)},"hover")
# plot(xvar, yvar)
})
main_plot %>% bind_shiny("plot1")
})
UI file: library(ggvis)
shinyUI(fluidPage(
titlePanel("Paid Search Report"),
fluidRow(
column(3,
wellPanel(
h2("Metrics"),
selectInput("xvar", "X-Axis Variable", axis_vars, selected = "Clicks"),
selectInput("yvar", "Y-Axis Variable", axis_vars, selected = "Cost")
)),
column(9,
ggvisOutput("plot1")
)
)))
Upvotes: 1
Views: 496
Reputation: 5346
I had the same problem but only a few points were disappearing, also the tooltip hover was going haywire!. Changing the rendering from svg to canvas fixed the issue for me.
Can be done using set_options(renderer = "canvas")
for the ggvis plot.
Upvotes: 0