简体   繁体   中英

Datatable and Highcharter in Shiny R

Is it possible to link datatable with highcharter? For example, click on any line of the table, the highcharter will show result in dynamic?

Here is an example, select any row you want and see the chart (highchart) react to selected values:

library(highcharter)
library(DT)
library(shiny)
db <- mtcars
ui <- fluidPage(DTOutput("my_dt"),
                highchartOutput("my_hc"))
server <- function(input, output, session) {
  output$my_dt <- renderDT({
    db
  })
  output$my_hc <- renderHighchart({
    db_hc <-
      db[input$my_dt_rows_selected, ] # filter dataset according to select rows in my_dt
    hc <- highchart() %>%
      hc_add_series(name = "mpg", data = db_hc$mpg) %>%
      hc_add_series(name = "wt", data = db_hc$wt)
    hc
  })
}

shinyApp(ui, server)

Hope it helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM