controller <- manipulateWidget(
{
dygraph(data[range[1]:range[2] - 2000, c("year", series)], main = title)
},
data = mwSharedValue(),
title = mwSharedValue(),
range = mwSlider(min = 2010,
max = 2001 + (nrow(data)-1), c(2001, 2001 + (nrow(data)-1))),
series = mwSelect(choices = colnames(data)[-1],
value = {colnames(data)[3]}, .display = TRUE),
.compare = c("series"),
.runApp = FALSE
)
library(dygraphs)
ui <- fillPage(
fillRow(
flex = c(NA, 1),
div(
textInput("title", label = "Title", value = "glop"),
sliderInput("obs", "Number of observations:",
min = 10, max = 1000, value = 500)
),
mwModuleUI("mw", height = "100%")
)
)
server <- function(input, output, session) {
data <- reactive({
if(runif(1) > 0.5){
data.frame(
year = 2000+1:input$obs,
series1 = rnorm(input$obs),
series2 = rnorm(input$obs),
series3 = rnorm(input$obs)
)
} else {
data.frame(
year = 2000+1:input$obs,
series1 = rnorm(input$obs),
series2 = rnorm(input$obs)
)
}
})
ctrl <- mwModule("mw", controller, data = data, title = reactive(input$title))
observeEvent(input$obs, {
ctrl$setValueAll("range", c(2001, 2001 + (nrow(data())-1)))
}, ignoreInit = TRUE)
}
shinyApp(ui, server)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.