Add_tooltip doesn't work in ggvis in R

I want to add a tooltip containing all the variables. But when I use this code, I get the following error:

Error in $ add handlers (handler, key, tail): key / is already in use

If I don't use it add_tooltip

, the plot is created without any problem. (Add_tooltip is at the bottom of the server .R)

Please help, I am really upset.

I am building a brilliant app with the following ui and server :

ui.R

library(ggplot2)
library(ggvis) 

library(shiny) # load shiny at beginning at both scripts
shinyUI(fluidPage( # standard shiny layout, controls on the
  # left, output on the right
  titlePanel("Relative Velocity vs Distance Gap"), # give the interface a title
  sidebarLayout(position="right",
                sidebarPanel( # all the UI controls go in here
                  radioButtons(inputId = 'dfid', label = h4("Select Data:"), 
                               choices = c("Coordinate Approach",
                                           "Sum Approach")),                  
                  selectInput(inputId="vid", label=h4("Select Vehicle ID:"), choices = vehid)
                ),
                mainPanel( # all of the output elements go in here

                  h3("Plot"), # title with HTML helper
                  plotOutput("plot") # this is the name of the output
                  # element as defined in server.R
                )
  )

))  

      

server.R

library(ggvis)  
library(shiny) # load shiny at beginning at both scripts
shinyServer(function(input, output) { # server is defined within
  # these parentheses

  new.data <- reactive({switch(input$dfid, "Coordinate Approach"=df1, "Sum Approach"=df2)})

  output$plot <- renderPlot({       

    new.data <- subset(new.data(), new.data()$Vehicle.ID==input$vid)
    tittle <- unique(new.data$Vehicle.class)

    mtc <- new.data
    mtc$id <- 1:nrow(mtc)

    all_values <- function(x) {
      if(is.null(x)) return(NULL)
      row <- mtc[mtc$id == x$id, ]
      paste0(names(row), ": ", format(row), collapse = "<br />")
    }

    mtc %>% ggvis(x = ~relative.v, y = ~gap.dist, key:=~id) %>%
      layer_points() %>%
      add_tooltip(all_values, "hover")  

    #ggplot(data= new.data, mapping = aes(x=relative.v, y=gap.dist, color=as.factor(p))) + 
     # geom_point() + ggtitle(tittle) + labs(x='Relative Velocity (ft/s)', y='Gap (feet)')  + theme_bw() #+ my.theme()

  })        
})

      

Another unrelated issue is that when the app is launched, the shiny app is launched in the window, but the ggvis graph is generated in the Viewer panel.

How can I display a plot in a window in the Shiny app?

+3
r ggvis


source to share


No one has answered this question yet

Check out similar questions:

8
Can't get interactive scaling to work with ggvis
6
magazine scale and limits with ggvis
4
Exclude line / dots from displaying information when using add_tooltip with hover in ggvis
2
R Hexadecimal colors don't work in ggvis
2
ggvis with tooltip not working with layer_smooths
1
adding centile overlay to ggplot in Shiny app
1
ggvis add_tooltip doesn't work with layer_bars
1
gliny and ggvis force () to resolve (before) bind_shiny ()
1
How do I display different colors on each side of the slider in the Shiny app? When you slide from either side, the color should also be filled automatically
0
how to calculate the area of ​​intersection of two circles in shiny or R code



All Articles
Loading...
X
Show
Funny
Dev
Pics