在两个图表上连接范围选择器

Connecting range selector on two graphs

我正在尝试构建一个闪亮的应用程序,其中两个 Dygraph 视觉效果由一个范围选择器控制。我不确定从哪里开始,我假设这是无法开箱即用的事情。是否需要另一个包来控制两个滑块?

ui.R

library(shiny)
library(dygraphs)



shinyUI(fluidPage(

  titlePanel("Education"),

  sidebarLayout(
    sidebarPanel(
      br("test")
    ),
    mainPanel(
      dygraphOutput("dygraph1"),
      dygraphOutput("dygraph2")
    )
  )
))

server.R

library(shiny)
library(dygraphs)



df_education <-  
read.csv("C:/Users/adarvishian/Documents/rworking/dygraphtest/education.csv")



education_subset <- df[c(12:55),c(3,8:11)]

w1 = 0.25
w2 = 0.25
w3 = 0.25
w4 = 0.25

education_subset$Index = w1*education_subset$Secondary.school.enrollment+w2*education_subset$Primary.school.enrollment+w3*education_subset$Preprimary.school.enrollment+w4*education_subset$Tertiary.school.enrollment


index_edu<- education_subset[,c(1,6)]



function(input, output){

  output$dygraph1 <- renderDygraph({
   dygraph(education_subset, main = "Education Components") %>%
      dyRangeSelector()

  })

  output$dygraph2 <- renderDygraph({
    dygraph(index_edu, main = "Education Index") %>%
      dyRangeSelector()
    })


}

数据

https://github.com/adarvishian/dygraphtest.git

似乎 dygraphs 库的 synchronization 功能可以让您到达您想去的地方?

如xo_gene所述,下面是相同的代码:

library(dygraphs)
library(datasets)



ui <- shinyUI(fluidPage(

    mainPanel(
      dygraphOutput("dygraph"),dygraphOutput("dygraph1"),dygraphOutput("dygraph2")
    )
  )
)

server <- shinyServer(function(input, output) {


  output$dygraph <- renderDygraph({
    dygraph(ldeaths, main = "All", group = "lung-deaths")
  })
  output$dygraph1 <- renderDygraph({
    dygraph(mdeaths, main = "Male", group = "lung-deaths")
  })
  output$dygraph2 <- renderDygraph({
    dygraph(fdeaths, main = "Female", group = "lung-deaths")
  })
})

shinyApp(ui = ui, server = server)