0

单击鼠标后,我需要能够向绘图添加另一个跟踪。我正在使用 R 的 Web 框架 Shiny 在 Web 浏览器中显示绘图。此时我要添加的系列是点或任何系列。

我还需要在情节上画线。我想点击一个起点和一个终点,一条线穿过点击的点。

这就是我到目前为止所拥有的。

#############To Update
#if (!require("devtools"))
#install.packages("devtools")
#devtools::install_github("jbkunst/highcharter")

library("shiny")
library("highcharter")

dots<-hc_add_series_scatter(cars$speed, cars$dist)

hc_base <- highchart() %>% 
  hc_xAxis(categories = citytemp$month) %>% 
  hc_add_series(name = "Tokyo", data = citytemp$tokyo) 

ui <- fluidPage(
  h2("Viewer"),
  fluidRow(
    h3(""), highchartOutput("hc_1", width = "100%", height = "800px"),
     h3("Click"), verbatimTextOutput("hc_1_input2")
  )
)
server = function(input, output) {
  output$hc_1 <- renderHighchart({
       hc_base %>% 
          hc_add_theme(hc_theme_ffx())%>%
                 hc_tooltip(backgroundColor="skyblue",crosshairs = TRUE, borderWidth = 5, valueDecimals=2)%>%
                      hc_add_event_series(series="dots", event = "click")
})
output$hc_1_input2 <- renderPrint({input$hc_1_click })
}
shinyApp(ui = ui, server = server)

任何帮助将不胜感激。

4

1 回答 1

1

这可能是一种方法:

library(shiny)
library(highcharter)


hc_base <- highchart() %>% 
  hc_xAxis(categories = citytemp$month) %>% 
  hc_add_series(name = "Tokyo", data = citytemp$tokyo) 

ui <- fluidPage(
  h2("Viewer"),
  fluidRow(
    h3(""), highchartOutput("hc_1", width = "100%", height = "800px"),
    h3("Click"), verbatimTextOutput("hc_1_input2")
  )
)
server = function(input, output) {
  output$hc_1 <- renderHighchart({
    hc_base %>% 
      hc_add_theme(hc_theme_ffx())%>%
      hc_tooltip(backgroundColor="skyblue",crosshairs = TRUE, borderWidth = 5, valueDecimals=2)%>%
      hc_add_event_point(event = "click")
  })

  observeEvent(input$hc_1_click,{
    output$hc_1 <- renderHighchart({
      hc_base %>% 
        hc_add_theme(hc_theme_ffx())%>%
        hc_tooltip(backgroundColor="skyblue",crosshairs = TRUE, borderWidth = 5, valueDecimals=2)%>%
        hc_add_series_scatter(cars$speed, cars$dist)
    })

  })

  output$hc_1_input2 <- renderPrint({input$hc_1_click })
}
shinyApp(ui = ui, server = server)

希望能帮助到你!

于 2017-03-15T10:28:43.727 回答