Opciones de JavaScript de diagramas simples en R / Shiny
¿Hay alguna manera de usar las opciones simples de JavaScript de Dygraphs en R (y Shiny más en específico)?
http://dygraphs.com/options.html
Pienso que elJS()
La función del paquete htmlwidgets puede ser útil, pero no estoy seguro.
Por ejemplo, quiero usarhighlightSeriesOpts
(véase el primer enlace) para resaltar series individuales en un diagrama de gráficos para mostrar SOLAMENTE las series seleccionadas en la leyenda (y no todas las series al mismo tiempo por defecto). Las 2 parcelas inferiores en el siguiente enlace muestran exactamente lo que se debe lograr:
http://dygraphs.com/gallery/#g/highlighted-series
Ya se ha proporcionado una solución CSS (es decir,.dygraph-legend {display: none;}
y.dygraph-legend .highlight {display: inline;}
), pero eso de alguna manera no funciona en R / Shiny.
De todos modos, aquí hay un guión conceptual mío. No funciona, pero todos los consejos son muy 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)