我需要能够在鼠标单击后向图中添加另一个跟踪。我正在使用R的Web Framework 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)
任何帮助将不胜感激。
这可能是一种方法:
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)
希望它有帮助!