shiny conditional css in dygraph

Hi

I need to change the appearance of dygraph legend dependent on input checkbox which switches highlighting on/off:
if highlighting off, legend of all series should appear, if highlighting on, only the selected (highlighted) value should appear in the legend.

I tried to achieve this by the method shown in the example code below, but it does not work.
(The idea is to apply the dyCSS to the dygraph only if the inputcheckbox has the value "True")

How can I solve this?
woec

library(shiny)
library(dygraphs)

lungDeaths <- cbind(ldeaths, mdeaths, fdeaths)

ui <- fluidPage(
  checkboxInput("hL","Highlight",value = F),
  br(),br(),
  dygraphOutput("dg")
)



server <- function(input,output,session){
  
  output$dg <- renderDygraph({
    g <- dygraph(lungDeaths, main = "Deaths from Lung Disease (UK)")
    if(input$hL) {
      g <- g %>% dyHighlight() %>% dyCSS(textConnection("
                    .dygraph-legend > span { display: none; }
                    .dygraph-legend > span.highlight { display: inline; }
                    "))
      }
    g
  })
}

shinyApp(ui,server)

You mean like this?

library(shiny)
library(dygraphs)

lungDeaths <- cbind(ldeaths, mdeaths, fdeaths)

ui <- fluidPage(
  checkboxInput("hL","Lung Deaths",value = F),
  br(),br(),
  dygraphOutput("dg")
)



server <- function(input,output,session){
  
  output$dg <- renderDygraph({

    g <- dygraph(lungDeaths, main = "Deaths from Lung Disease (UK)")
    if(input$hL == "TRUE") {
    g <- dygraph(lungDeaths[, "ldeaths"], main = "Deaths from Lung Disease (UK)")
    }
    g
  })
}

shinyApp(ui,server)

Hi,

no, your suggestion switches off the whole series. I want to switch off just the legend of the series not highlighted.
You can see the desired effect by commenting out the if condition. Then, you can see the desired behavior with highlighting switched on.

woec

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.