添加工具提示在R中的ggvis中不起作用

添加工具提示在R中的ggvis中不起作用,r,ggvis,R,Ggvis,我想添加包含所有变量的工具提示。 但当我使用此代码时,会出现以下错误: 处理程序$add(handler,key,tail)中出错:key/已在使用中 如果我不使用add\u工具提示,则创建绘图时不会出现任何问题。 (添加工具提示位于server.R的底部附近) 请帮忙,我真的很沮丧 我正在使用以下ui和服务器创建一个闪亮的应用程序: library(ggplot2) library(ggvis) library(shiny) # load shiny at beginning at bot

我想添加包含所有变量的工具提示。 但当我使用此代码时,会出现以下错误:

处理程序$add(handler,key,tail)中出错:key/已在使用中

如果我不使用
add\u工具提示
,则创建绘图时不会出现任何问题。 (添加工具提示位于server.R的底部附近)

请帮忙,我真的很沮丧

我正在使用以下ui服务器创建一个闪亮的应用程序:

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
                )
  )

))  
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()

  })        
})
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
                )
  )

))  
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()

  })        
})
服务器.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
                )
  )

))  
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()

  })        
})
库(ggvis)
库(闪亮)#在两个脚本的开头加载闪亮
shinyServer(函数(输入、输出){#服务器定义在
#这些括号
新数据