Plain Dygraphs JavaScript options in R/Shiny

后端 未结 1 522
Happy的楠姐
Happy的楠姐 2021-01-07 06:43

Is there a way to use plain Dygraphs JavaScript options in R (and Shiny more in specific)?
http://dygraphs.com/options.html

I think the JS() functio

1条回答
  •  遥遥无期
    2021-01-07 07:39

    The highlightSeriesOpts causes the highlighted series stroke to be bolder and does not affect the legend. You will still need the proper CSS to only show the closest series in the legend. To set the highlightSeriesOpts as you suggest, there is a clear example at http://rstudio.github.io/dygraphs/gallery-series-highlighting.html.

    lungDeaths <- cbind(ldeaths, mdeaths, fdeaths)
    
    dygraph(lungDeaths, main = "Deaths from Lung Disease (UK)") %>%
      dyHighlight(highlightSeriesOpts = list(strokeWidth = 3))
    

    For a fuller answer in Shiny, we could do something like this.

    library(shiny)
    library(dygraphs)
    
    lungDeaths <- cbind(ldeaths, mdeaths, fdeaths)
    
    ui <- dygraph(lungDeaths, main = "Deaths from Lung Disease (UK)") %>%
      dyHighlight(highlightSeriesOpts = list(strokeWidth = 3)) %>%
      dyCSS(textConnection("
         .dygraph-legend > span { display: none; }
         .dygraph-legend > span.highlight { display: inline; }
      "))
    
    server <- function(input,output,session){
    
    }
    
    shinyApp(ui,server)
    

    0 讨论(0)
提交回复
热议问题