daattali / timevis

📅 Create interactive timeline visualizations in R
http://daattali.com/shiny/timevis-demo/
Other
653 stars 157 forks source link

Add documentation about how to add custom style to timevis #45

Closed daattali closed 5 years ago

daattali commented 6 years ago

When not in shiny:

## the data argument: three items
dtable <- data.frame(
    group = c("confirmed", "possible", "eclipse"),
    content = c("Susan and Martha", "Roger", "Eclipse"),
    start = c("2018-01-23", "2018-01-27", "2018-01-31"),
    end = c("2018-02-03", "2018-02-01", NA),
    className = c("confirmed", "possible", "eclipse"))
## the groups argument: three groups.  re-use 'id' as 'className'
## (could be different)
gtable <- data.frame(
    id = c("eclipse", "confirmed", "possible"),
    content = c("Eclipse", "confirmed", "possible"),
    title = c("Eclipse itself",
              "people who are 100% (+/-) planning on coming at this time",
              "people who have said they might come at this time"),
    className = c("eclipse", "confirmed", "possible"))
## style for data strips' background color, group label color
styles <- "
.vis-item.possible { background-color: LightGray; }
.vis-item.confirmed { background-color: Khaki; }
.vis-item.eclipse { background-color: MediumSeaGreen; }

.vis-labelset .vis-label.possible { color: Black; }
.vis-labelset .vis-label.confirmed { color: #71670f; }
.vis-labelset .vis-label.eclipse { color: #004d00; }"

## create visualization object
tv <- timevis(data=dtable, groups=gtable)

## the object returned by timevis() is of class c("timevis",
## "htmlwidget").  one can run htmltools methods on it.  so, add our
## styles to tv.
tv <- tagList(list(tags$head(tags$style(styles, type="text/css")), tv))

## (after this, tv is of class c("shiny.tag.list", "list"))

html_print(tv)                          # display