# For more examples, see http://daattali.com/shiny/timevis-demo/
### Most basic
timevis()
### Minimal data
timevis(
data.frame(id = 1:2,
content = c("one", "two"),
start = c("2016-01-10", "2016-01-12"))
)
### Hide the zoom buttons, allow items to be editable (add/remove/modify)
timevis(
data.frame(id = 1:2,
content = c("one", "two"),
start = c("2016-01-10", "2016-01-12")),
showZoom = FALSE,
options = list(editable = TRUE, height = "400px")
)
### Items can be a single point or a range, and can contain HTML
timevis(
data.frame(id = 1:2,
content = c("one", "two<br><h3>HTML is supported</h3>"),
start = c("2016-01-10", "2016-01-18"),
end = c("2016-01-14", NA))
)
### Alternative look for each item
timevis(
data.frame(id = 1:2,
content = c("one", "two"),
start = c("2016-01-10", "2016-01-18"),
end = c("2016-01-14", NA),
type = c("background", "point"))
)
### Using a function in the configuration options
timevis(
data.frame(id = 1,
content = "double click anywhere<br>in the timeline<br>to add an item",
start = "2016-01-01"),
options = list(
editable = TRUE,
onAdd = htmlwidgets::JS('function(item, callback) {
item.content = "Hello!<br/>" + item.content;
callback(item);
}')
)
)
### Having read-only and editable items together
timevis(
data.frame(id = 1:2,
content = c("editable", "read-only"),
start = c("2016-01-01", "2016-01-18"),
editable = c(TRUE, FALSE),
style = c(NA, "background: red; color: white;"))
)
### Getting data out of the timeline into Shiny
if (interactive()) {
library(shiny)
data <- data.frame(
id = 1:3,
start = c("2015-04-04", "2015-04-05 11:00:00", "2015-04-06 15:00:00"),
end = c("2015-04-08", NA, NA),
content = c("<h2>Vacation!!!</h2>", "Acupuncture", "Massage"),
style = c("color: red;", NA, NA)
)
ui <- fluidPage(
timevisOutput("appts"),
div("Selected items:", textOutput("selected", inline = TRUE)),
div("Visible window:", textOutput("window", inline = TRUE)),
tableOutput("table")
)
server <- function(input, output) {
output$appts <- renderTimevis(
timevis(
data, getSelected = TRUE, getData = TRUE, getWindow = TRUE,
options = list(editable = TRUE, multiselect = TRUE, align = "center")
)
)
output$selected <- renderText(
paste(input$appts_selected, collapse = " ")
)
output$window <- renderText(
paste(input$appts_window[1], "to", input$appts_window[2])
)
output$table <- renderTable(
input$appts_data
)
}
shinyApp(ui, server)
}
Run the code above in your browser using DataLab