How to show qualitative values when hovering on dygraph in R-Shiny?

116 Views Asked by At

I have a time-series of quantitative and qualitative data. I am trying to plot a time-series of the data with dyGraphs, but I also want to be able to view the qualitative data when I hover over a certain point.

Something like this:

library(shiny)
library(dygraphs)
library(xts)

my_data <- data.frame("date" = ymd(c("2020-01-01", "2020-02-01", "2020-03-01")),
                      "quan1" = c(1, 2, 3),
                      "quan2" = c(6, 5, 4),
                      "qual1" = c("a", "b", "c"),
                      "qual2" = c("f", "e", "d"))

ui <- fluidPage(
  dygraphOutput("mygraph")
)

server = function(input, output, session) {
  output$mygraph <- renderDygraph({
    my_data_xts <- xts(x = my_data, order.by = my_data$date)
    dygraph(my_data_xts, main = "My Graph") #%>%
      #something like: dyHover("qual1", "qual2") ???
  })
}

shinyApp(ui = ui, server = server)

When I run this, the graph seems to recognise that the qualitative series are included (lines are shown in the legend), but it only gives me the values of the two quantitative series when I hover over a point.

I have had a look through the information at https://rstudio.github.io/dygraphs/ and can't see it anywhere there.

Is there any way I can get it to also show the qualitative values when I hover each point?

Thanks!

0

There are 0 best solutions below