Opções de JavaScript de Dygraphs simples em R / Shiny
Existe uma maneira de usar opções simples de JavaScript Dygraphs no R (e Shiny mais em específico)?
http://dygraphs.com/options.html
Eu acho que oJS()
A função do pacote htmlwidgets pode ser útil, mas não tenho certeza.
Por exemplo, eu quero usarhighlightSeriesOpts
(consulte o primeiro link) para realçar séries individuais em um gráfico de dígrafos para exibir SOMENTE as séries selecionadas na legenda (e nem todas as séries ao mesmo tempo por padrão). Os 2 gráficos inferiores no link a seguir mostram exatamente o que deve ser alcançado:
http://dygraphs.com/gallery/#g/highlighted-series
Uma solução CSS já foi fornecida (ou seja,.dygraph-legend {display: none;}
e.dygraph-legend .highlight {display: inline;}
), mas que de alguma forma não funciona no R / Shiny.
De qualquer forma, aqui está um roteiro conceitual meu. Não funciona, mas todos os conselhos são muito apreciados.
ui <- fluidPage(
sidebarLayout(
sidebarPanel(),
mainPanel(dygraphOutput("plot"))
)
)
server <- function(input, output) {
set.seed(123)
data <- matrix(rnorm(12), ncol = 2)
data <- ts(data)
# Workaround for what might be a bug
# Reference: http://stackoverflow.com/questions/28305610/use-dygraph-for-r-to-plot-xts-time-series-by-year-only
data <- cbind(as.xts(data[,1]), as.xts(data[,2]))
colnames(data) <- c("Series 1", "Series 2")
#print(data) # Uncomment to view data frame
# The logic of the following is that plain Dygraphs JavaScript
# code can be used as plotting material
output$plot <- JS("
new Dygraph(plot,
data,
{ highlightSeriesOpts: {strokeWidth: 3} });
g.updateOptions({ highlightSeriesOpts: {strokeWidth: 3} });
")
}
shinyApp(ui = ui, server = server)