Giter Site home page Giter Site logo

daattali / timevis Goto Github PK

View Code? Open in Web Editor NEW
644.0 37.0 157.0 830 KB

πŸ“… Create interactive timeline visualizations in R

Home Page: http://daattali.com/shiny/timevis-demo/

License: Other

R 78.94% CSS 6.20% JavaScript 14.87%
shiny shiny-r r rstats r-package

timevis's Introduction

timevis

πŸ“… Create interactive timeline visualizations in R

Demo Β· by Dean Attali

R build status CRAN version


{timevis} lets you create rich and fully interactive timeline visualizations in R. Timelines can be included in Shiny apps or R markdown documents. {timevis} includes an extensive API to manipulate a timeline after creation, and supports getting data out of the visualization into R. This package is based on the visjs Timeline JavaScript library.

Need Shiny help? I'm available for consulting.
If you find {timevis} useful, please consider supporting my work! ❀

This package is part of a larger ecosystem of packages with a shared vision: solving common Shiny issues and improving Shiny apps with minimal effort, minimal code changes, and clear documentation. Other packages for your Shiny apps:

Package Description Demo
shinyjs πŸ’‘ Easily improve the user experience of your Shiny apps in seconds πŸ”—
shinyalert πŸ—―οΈ Easily create pretty popup messages (modals) in Shiny πŸ”—
shinyscreenshot πŸ“· Capture screenshots of entire pages or parts of pages in Shiny apps πŸ”—
shinycssloaders βŒ› Add loading animations to a Shiny output while it's recalculating πŸ”—
colourpicker 🎨 A colour picker tool for Shiny and for selecting colours in plots πŸ”—
shinybrowser 🌐 Find out information about a user's web browser in Shiny apps πŸ”—
shinydisconnect πŸ”Œ Show a nice message when a Shiny app disconnects or errors πŸ”—
shinytip πŸ’¬ Simple flexible tooltips for Shiny apps WIP
shinymixpanel πŸ” Track user interactions with Mixpanel in Shiny apps or R scripts WIP
shinyforms πŸ“ Easily create questionnaire-type forms with Shiny WIP

Demo

Click here to view an interactive demo of many {timevis} features.

If you create a cool timeline with {timevis}, I’d love to hear about it!

Sponsors πŸ†

There are no sponsors yet

Become the first sponsor for {timevis}!

Table of contents

Installation

For most users: To install the stable CRAN version:

install.packages("timevis")

For advanced users: To install the latest development version from GitHub:

install.packages("remotes")
remotes::install_github("daattali/timevis")

How to use

You can view a minimal timeline without any data by simply running

library(timevis)
timevis()

Minimal timeline

You can add data to the timeline by supplying a data.frame

data <- data.frame(
  id      = 1:4,
  content = c("Item one"  , "Item two"  ,"Ranged item", "Item four"),
  start   = c("2016-01-10", "2016-01-11", "2016-01-20", "2016-02-14 15:00:00"),
  end     = c(NA          ,           NA, "2016-02-04", NA)
)

timevis(data)

Basic timeline

Every item must have a content and a start variable. If the item is a time range rather than a single point in time, you can supply an end as well. id is only required if you want to access or manipulate an item.

There are more variables that can be used in the data.frame – they are all documented in the help file for ?timevis() under the Data format section.

By default, a timeline will show the current date as a red vertical line and will have zoom in/out buttons. You can supply many customization options to timevis() in order to get it just right (see ?timevis() for details).

Slightly more advanced examples

The content of an item can even include HTML, which makes it easy to show any kind of data in a timeline, such as the matches of the 2014 World Cup:

World cup timeline

If you know some CSS, you can completely customize the look of the timeline:

Custom style timeline

Interactivity

The timeline lets the user interact with it seamlessly. You can click on the zoom in/out buttons or drag the timeline left/right in order to move to past/future dates.

If you set the editable = TRUE option, then the user will be able to add new items by double clicking, modify items by dragging, and delete items by selecting them.

Groups

You can use the groups feature to group together multiple items into "buckets". When using groups, all items with the same group are placed on one line. A vertical axis is displayed showing the group names. Grouping items can be useful for a wide range of applications, for example when showing availability of multiple people, rooms, or other resources next to each other. You can also think of groups as "adding a Y axis".

Here is an example of a timeline that has four groups: "Gym", "Pool", "Sauna", "Hot Tub":

Groups timeline

In order to use groups, items in the data need to have group ids, and a separate dataframe containing the group information needs to be provided. More information about using groups is available in the help file for ?timevis() under the Groups section.

Groups can also contain nested groups. The next example is similar to the previous one, except "Sauna" and "Hot Tub" are now nested under "Pool":

Nested groups timeline

Refer to the visjs Timeline documentation to see all the options that are supported.

Functions to manipulate a timeline

There are many functions that allow programmatic manipulation of a timeline. For example: addItem() programmatically adds a new item, centerItem() moves the timeline so that a given item is centered, setWindow() sets the start and end dates of the timeline, setOptions() updates the configuration options, and many more functions are available.

There are two ways to call these timeline manipulation functions:

1. Timeline manipulation using %>% on timevis()

You can manipulate a timeline widget during its creation by chaining functions to the timevis() call. For example:

timevis() %>%
  addItem(list(id = "item1", content = "one", start = "2016-08-01")) %>%
  centerItem("item1")

This method of manipulating a timeline is especially useful when creating timeline widgets in the R console or in R markdown documents because it can be used directly when initializing the widget.

2. Timeline manipulation using a timeline’s ID

In Shiny apps, you can manipulate a timeline widget at any point after its creation by referring to its ID. For example:

library(shiny)

ui <- fluidPage(
  timevisOutput("mytime"),
  actionButton("btn", "Add item and center")
)

server <- function(input, output, session) {
  output$mytime <- renderTimevis(timevis())
  observeEvent(input$btn, {
    addItem("mytime", list(id = "item1", content = "one", start = "2016-08-01"))
    centerItem("mytime", "item1")
  })
}

shinyApp(ui = ui, server = server)

You can even chain these functions and use this manipulation code instead of the bold code:

addItem("mytime", list(id = "item1", content = "one", start = "2016-08-01")) %>%
  centerItem("item1")

Technical note: If you’re trying to understand how both methods of timeline manipulation work, it might seem very bizarre to you. The reason they work is that every manipulation function accepts either a timevis object or the ID of one. In order to make chaining work, the return value from these functions depend on the input: if a timevis object was given, then an updated timevis object is returned, and if an ID was given, then the same ID is returned.

Extending timevis

If you need to perform any actions on the timeline object that are not supported by the {timevis} API, you may be able to do so by manipulating the timeline's JavaScript object directly. The timeline object is available via document.getElementById("id").widget.timeline (replace id with the timeline's id).

This timeline object is the direct widget that vis.js creates, and you can see the visjs documentation to see what actions you can perform on that object.

In a Shiny app

You can add a timeline to a Shiny app by adding timevisOutput() to the UI and renderTimevis(timevis()) to the server.

Retrieving data from the widget

It is possible to retrieve data from a timeline in a Shiny app. When a timeline widget is created in a Shiny app, there are four pieces of information that are always accessible as Shiny inputs. These inputs have special names based on the timeline’s id. Suppose that a timeline is created with an outputId of "mytime", then the following four input variables will be available:

  • input$mytime_data - will return a data.frame containing the data of the items in the timeline. The input is updated every time an item is modified, added, or removed.
  • input$mytime_ids - will return the IDs (a vector) of all the items in the timeline. The input is updated every time an item is added or removed from the timeline.
  • input$mytime_selected - will return the IDs (a vector) of the selected items in the timeline. The input is updated every time an item is selected or unselected by the user. Note that this will not get updated if an item is selected programmatically using the API functions.
  • input$mytime_window - will return a 2-element vector containing the minimum and maximum dates currently visible in the timeline. The input is updated every time the viewable window of dates is updated (by zooming or moving the window).
  • input$mytime_visible - will return a list of IDs of items currently visible in the timeline.

Crosstalk support

{timevis} is fully compatible with crosstalk. This means that you can provide it with a crosstalk SharedData object to select/filter data across multiple Shiny widgets.

Here is a simple example:

df <- data.frame(start = c(Sys.Date(), Sys.Date() - 1, Sys.Date() - 2), content = 1:3)
shared_df <- crosstalk::SharedData$new(df)
crosstalk::bscols(
  timevis(shared_df, options = list(multiselect = TRUE), showZoom = FALSE, width = "100%"),
  DT::datatable(shared_df)
)

If you select any events in the timeline (use ctrl or shift to select multiple events), then the table will automatically select those as well, and vice versa.


You can view examples of many of the features supported by checking out the demo Shiny app. If you want to see how those examples were created, the full code for the examples is inside inst/example.

Lastly, if you want to learn how to develop an htmlwidget to have similar features as this package, you can check out the timevisBasic package or my tutorial on htmlwidgets tips.

Credits

Logo design by Alfredo HernΓ‘ndez.

timevis's People

Contributors

daattali avatar emillykkejensen avatar mhtorp avatar muschellij2 avatar nfultz avatar strazto avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

timevis's Issues

Translating Date Timeline

@daattali , nice job! This is a awesome package that helps me a lot.

I would like to know if its possible to configurate timevis() to return de description of the month in others languages. I mean that always I use tivevis() the time line of months comes like "August 2014", "September 2014"... and I would to find a way to translate it before plot. Is it possible?

Label text: does not bleed over

timevis_bleed

When run using RStudio, the label text does not bleed over the labels

That is, if the width of the text is longer than the width of the label box, then the text is cut off. In the examples online, the text extends beyond label box

When re-rendering a timeline, the old data are not removed

Bug reported to me via private email.

Example:

library(shiny)
library(timevis)

ui <- fluidPage(
  timevisOutput("timeline"),
  textInput("text", "Text", "Hello")
)

server <- function(input, output, session) {
  output$timeline <- renderTimevis(
    timevis(data.frame(start = Sys.Date(), content = input$text))
  )
}

shinyApp(ui = ui, server = server)

Every time you change the text, a new item gets added but all the previous ones still exist. That's a clear bug and not how it should work.

Google Chrome does not render correctly 4000 years bC.

Hi daattali,

Thank you for 'timevis'. I just need to make a timeline that goes 4000 years bC. It renders well in RStudio but not in Google Chrome (not tested in other browsers).

You may want to check on this.

Code:

`
data <- data.frame(
id = 1:4,
content = c("4000 years - Before JesusChrist", "History changes" ,"Ranged item", "Item four"),
start = c("-4000","0000-01-01", "2016-01-20", "2016-02-14"),
end = c(NA , NA, "2016-02-04", NA)
)

timevis(data)
`

RStudio:

rstudio-timevis

Google Chrome:

googlechrome-timevis

Using observeEvent causes rendering issues

When utilizing observe event for a submission to look at a subset of a possible renderTimevis, after the first selection each new subset selected to view adds additional entries above the existing selection rather than overwriting and clearing the previous selection.

is it possible to use hover

hello,
we implemented gantt chart using timevis,
we having some question.

is it possible to hover method for task name's display when hover anywhere inside task bar?
is it possible to see output at every bar end side and multiple values seems for one output ?
is it possible to set some different color as per different categories.

we really need this two things if possible then let us know ASAP, that how can we implement this.
Thanks.

no package called 'stringi'

Rad idea! Thanks for working on this! Getting this error:

library(timevis) timevis()

Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) :
there is no package called β€˜stringi’``

Error message

For the longest time, my data was not showing up when I ran the timevis() function. Instead, I would receive an empty timeline. Finally, I figured out that I did not have fully unique ids in my data. Would have been wonderful if there had been some sort of data error message to help me figure this out.

timevis and visNetwork do not work together in the same app

They both use vis.js library so they are somehow conflicting with each other

Sample code:

library(timevis)
library(shiny)
library(visNetwork)

nodes <- data.frame(id = 1:3)
edges <- data.frame(from = c(1,2), to = c(1,3))

dataBasic <- data.frame(
  id = 1:4,
  content = c("Item one", "Item two" ,"Ranged item", "Item four"),
  start   = c("2016-01-10", "2016-01-11", "2016-01-20", "2016-02-14"),
  end    = c(NA, NA, "2016-02-04", NA)
)

ui<-fluidPage(
  timevisOutput('timeline'),
  visNetworkOutput('snagraph')
)

server<-function(input,output)({

  output$snagraph<-renderVisNetwork(visNetwork(nodes,edges))
  output$timeline<-renderTimevis(timevis(dataBasic)) 

}
)

shinyApp(ui,server)

subgroupOrder syntax

Not so much an issue, but I'm curious what the syntax is for the subgroupOrder argument. I haven't seen it in the code here or in the help via ?timevis(). Thanks.

Shiny input variable of visible items in timeline

Create a Shiny input variable of items visible in the timeline. Use visjs method getVisibleItems() to populate a vector of IDs inside a timeline.on(β€˜rangechanged’… listener.

Something like:

// The range of the window has changes (by dragging or zooming)                                             
timeline.on('rangechanged', function (properties) {
  Shiny.onInputChange(
    elementId + "_visible",
    timeline.getVisibleItems()
  );
});
Shiny.onInputChange(
  elementId + "_visible",
  timeline.getVisibleItems()
);

Group Order

I'm struggling with ordering groups. I've used the following syntax to order my data.frame alphabetically by country name.

Data <- Data[order(Data$Country), ])

However, when displaying the groups, only some, but not all groups are displayed alphabetically. I'd say it gets about 90% correct.

I also looked at the JS documentation and found groupOrder, but haven't figured out how to implement that.

Any advice would be helpful. Thanks!

timeline date formate can not modify

I want modify month format to Number(1-12)

  • config methods fail all
dataBasic <- data.frame(
  id = 1:4,
  content = c("Item one", "Item two" ,"Ranged item", "Item four"),
  start   = c("2016-01-10", "2016-01-11", "2016-01-20", "2016-02-14"),
  end    = c(NA, NA, "2016-02-04", NA)
)

# list style
config <- list(format = list(minorLabels = list(month = 'M')))

# json string
config <- list(
      format = "
      {
  minorLabels: {
    millisecond:'SSS',
    second:     's',
    minute:     'HH:mm',
    hour:       'HH:mm',
    weekday:    'ddd D',
    day:        'D',
    week:       'w',
    month:      'M',
    year:       'YYYY'
  },
  majorLabels: {
    millisecond:'HH:mm:ss',
    second:     'D MMMM HH:mm',
    minute:     'ddd D MMMM',
    hour:       'ddd D MMMM',
    weekday:    'MMMM YYYY',
    day:        'MM YYYY',
    week:       'M YYYY',
    month:      'YYYY',
    year:       ''
  }
}
      "
    )

timevis(dataBasic, zoomFactor = 1, options = config)
  • replace month:"MMM" to month:"M" in js file vis.min.js in R package timevis (failed)

Sizing Policy in R Markdown

Hi Dean,

First of all, I love the package!

Do you have any insights/examples on how to work with the sizing policy of the timevis in an R Markdown HTML document? Is there a way to have the height of the htmlwidget reflow dynamically?

Thanks,

example of custom css?

Hi there,

Thanks for the great R package! I can't find the code used to create the sample data in the "slightly more advanced examples" section of the vignette - specifically I'm having trouble formatting my own dataframe with the css components in the className and style columns to make it look like the png in the vignette (or something like it). Can you point me to where the code that includes the css is?

Thanks so much,
Myfanwy

Stacking Weird

Hi I have a problem that may well be of my own doing, but I don't see it.

Instead of plotting the observations sequentially, they are being stacked after the 9th one.

I have the following code;

`
library(timevis)
library(lubridate)
indexdate <- "2014-01-01" %>% as.Date()

twelveMo <- data.frame(
content = c(paste0(rep("predictor_"),1:12), paste0(rep("event_"),1:12)),
start = c(seq.Date(indexdate, by= "month", length.out = 12),
seq.Date(indexdate %m+% months(12), by= "month", length.out = 12) ),
end = c(seq.Date(indexdate %m+% months(12), by= "month", length.out = 12),
seq.Date(indexdate %m+% months(15), by= "month", length.out = 12)),
group = c(rep(1:12), rep(1:12)))

twelveMo

timevis(twelveMo, groups = data.frame(id = 1:12, content = c(paste0(rep("G_"),1:12))))`

weirdstacking

vis 4.19.1

May want to update to the js 4.19
Im assuming between their 4.16. and 4.19, they added the group nesting functionality. Spent a while trying to figure out why i couldnt get it to work haha. I did switch out the files in my local lib and ran my nested timeline, that worked, i ran your current sample app and initially World Cup and Groups tab did not work, after looking into it, those were the only 2 tabs that were using your datetime string. I removed the times and now everything works on this this version. So just need to check on the required datetime format.

thanks

vis.map not found

with a running timeline, if i open the "web inspector" (developer console), i see a message:
Failed to load resource: the server responded with a status of 404 (Not Found)
for the file "lib/vis-4.16.1/vis.map". if i add this file (from the vis.js distribution), this error message (which is probably indicative of nothing major) goes away. cheers!

TypeError: vis.Timeline is not a constructor

When running a simple example, I get the error in the javascript console "TypeError: vis.Timeline is not a constructor[Learn More]" and the output doesn't show up.

The example is a module in a bigger app. This happens only on my Linux machine, not on my windows.

library(timevis)
ui <- function(id){
  ns <- NS(id)
  fluidPage(h3("Timeline:"),
            timevisOutput(ns("timeline")))
}

server <- function(input, output, session) {
    output$timeline <- renderTimevis(
      timevis()
    )
}

shinyApp(ui, server)

R version 3.3.2 (2016-10-31)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: CentOS Linux 7 (Core)

Group colours

Is it possible to have a column in the dataframe or an argument to timevis which affects the colour of the bars and points ? I've tried the 'style' argument, but that only affects the label on the LHS of the graph.

My preference would really be to have an argument that allowed timevis to select the colours automatically depending on the number of groups and assign them itself.

Cheers
Pete

timevis and visnetwork can not be used together in Shiny

I am trying to include the timevis package and the visnetwork package into my Shiny app. but i find it did not work when i put them together.
and there are no errors. could you help me see what is the reason? appreciate for your any help.

here is the code below, please refer to it.

**library(timevis)
library(shiny)
library(visNetwork)

nodes <- data.frame(id = 1:3)
edges <- data.frame(from = c(1,2), to = c(1,3))

dataBasic <- data.frame(
id = 1:4,
content = c("Item one", "Item two" ,"Ranged item", "Item four"),
start = c("2016-01-10", "2016-01-11", "2016-01-20", "2016-02-14"),
end = c(NA, NA, "2016-02-04", NA)
)

ui<-fluidPage(
timevisOutput('timeline'),
visNetworkOutput('snagraph')
)

server<-function(input,output)({

output$snagraph<-renderVisNetwork(visNetwork(nodes,edges))
output$timeline<-renderTimevis(timevis(dataBasic))

}
)

shinyApp(ui,server)**

Add documentation about how to add custom style to timevis

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

Feature Request - Groups

Great library!

I wondered if you had looked to support groups in the future, a la http://visjs.org/examples/timeline/other/groupsPerformance.html

There are few good htmlwidget solutions for Gantt charts I have been able to find, in fact the only solution I've found thus far depends on plotly converting a ggplot2 plot:

timeline_data <- read.csv(file="https://ndownloader.figshare.com/files/5533355")
timeline_data$Start.Date <- as.Date(timeline_data$Start.Date)
timeline_data$End.Date <- as.Date(timeline_data$End.Date)
label_column <- "Prime.Minister"
category_column <- "Political.Party"
earliest_date_by_Prime_Minister <-
  timeline_data[timeline_data$Start.Date == ave(timeline_data$Start.Date, timeline_data$Prime.Minister, FUN =
                                                  min), ]
earliest_date_by_Prime_Minister <-
  earliest_date_by_Prime_Minister[order(
    earliest_date_by_Prime_Minister$Start.Date,
    earliest_date_by_Prime_Minister$Prime.Minister), ]
timeline_data$Prime.Minister <-
  factor(timeline_data$Prime.Minister, levels = rev(as.character(unique(earliest_date_by_Prime_Minister$Prime.Minister))))
timeline_data <- timeline_data[!is.na(timeline_data$End.Date) & !is.na(timeline_data$Start.Date),]
party_colours <- list("Labour" = "#DC241f", "Conservatives" = "#0087DC", "Liberal Democrat" = "#FDBB30")
party_colours <- as.character(party_colours[levels(timeline_data$Political.Party)])
gantt_labeler <- function(start_date = NA, end_date = NA, y_axis = NA, color = NA){
  paste0(
    "Prime Minister: ", y_axis, "</br>",
    "Date Range: ", start_date," to ",end_date,
    "</br>",
    "Political Party: ",color
  )
}
library(ggplot2)
library(plotly)
ggplotly(
  ggplot(
    data = timeline_data,
    aes(
      x = Start.Date,
      xend = End.Date,
      y = eval(as.name(label_column)),
      yend = eval(as.name(label_column)),
      colour = eval(as.name(category_column)),
      text = gantt_labeler(start_date = Start.Date, end_date = End.Date, y_axis = eval(as.name(label_column)), color = eval(as.name(category_column)))
    )
  ) + geom_segment(size = 3) + xlab("Date") + ylab("Prime Minister") + scale_colour_manual(name = "Political Parties",values = party_colours),
  tooltip = "text"
)

image

Issues with zooming when vis 4.20 is loaded (with visNetwork for example)

The latest visNetwork updates use vis 4.20 which overrides timevis' vis 4.16. As a result, the zoom functionality breaks when zoomed to show months.

Here's a reproducible example (note the version numbers).

ps. Love your work, Dean :)

library(shiny)
library(timevis) #0.4.0.9000
library(visNetwork) #2.0.2

server <- function(input, output) {
   output$timevis <- renderTimevis({
      timevis()
   })

   output$visnet <- renderVisNetwork({
      visNetwork()
   })
}

ui <- fluidPage(
   useShinyjs(),
   sidebarLayout(
      sidebarPanel(),
      mainPanel(
         timevisOutput("timevis"),
         visNetworkOutput("visnet")
      )
   )
)

shinyApp(ui = ui, server = server)

saving the timeline as png

How can I save a timeline as a png file?

The following code did not work, the resulting file myTimeLine.png could not be opened.

myTimeline<-timevis(
data.frame(id = 1:2,
content = c("one", "two"),
start = c("2016-01-10", "2016-01-12"))
)
htmlwidgets::saveWidget(myTimeline, "myTimeLine.png", selfcontained = T)

dependencies not automatically installed

When installing from CRAN, timevis does not automatically install xtable if it is not present but then fails to load if its not installed. I know several other packages automatically install their dependencies on install if needed.

Leading whitespace when getting selected item Id as a string

When retrieving the Id of (timeline)_selected as a string, whitespace is added to the beginning of the string under the following conditions

  1. There are Ids of varying length on the timeline (ex. 1, 12)
  2. The Id retrieved has fewer digits than the highest Id on the timeline

For example, when I have 10 items on a timeline with the Ids 1 through 10, getting the Id of item 4 as a string returns " 4" instead of "4". This seems to only occur when there are 10 or more items, implying that the lengths of all Ids are the same, regardless of the actual value.

Locale support

Hi Dean and thanks for the great package.

I'd like to use it but with a French locale which is not natively supported by vis.js. It is possible to include moment.js with locales in the page in order to have locale support, which is great.

However, moment needs to be included before vis.js for this to work. So I tried several things:

  1. the easiest is to add moment-with-locales.min.js as the first dependency in timevis.yaml, which is what I've done locally but including a 280KB library for a specific use case seems overkill,
  2. I tried adding the dependency dynamically in timevis.R this way:
if (!is.null(options$locale)) {
    deps <- c(
      deps,
      list(
        htmltools::htmlDependency(
          name = "moment",
          version = "2.17.1",
          src = system.file("htmlwidgets/lib/moment-2.17.1", package = "timevis"),
          script = "moment-with-locales.min.js"
        )
      )
    )
  }

which does not work because these dependencies are included after the ones in the YAML config file

  1. it's the same problem when trying to include it directly in a Shiny app with tags$head(tags$script(src = ...)), it is loaded after all the other dependencies

So do you have any ideas how to proceed from there ? Maybe updating the html_dependency structure from htmltools in order to include an include_before field ?

Thanks,
Pierre

Group Color

Not really an issue but a cool feature I think might be useful. Suppose in our data we have 2 categorical columns, 1 can be grouped as row label as of now, wouldn't it be great if the other one can be shown using color-coding, that is, data in the same group appear in the same color. It would add another dimension to our visualization tool.

It looks something like this
example

'verticalScroll' option can not work on my end

I want to add a vertical bar to the Gantt Chart so that I can scroll vertically. There is a 'verticalScroll' option in Timeline library in Javascript, but it can not work when I tried this option in R Timevis. Since the Timevis library in R is binding to the Timeline library in JS, I expect the options in JS should also work in R. Not sure if there is any problem on my end. Really appreciate it if you can contribute your ideas!

Here is a sample code I tried but failed to get the 'vertical scroll' feature:

`library(shiny)
library(timevis)

data <- data.frame(
id = 1:4,
content = c("Item one", "Item two",
"Ranged item", "Item four"),
start = c("2016-01-10", "2016-01-11",
"2016-01-20", "2016-02-14 15:00:00"),
end = c(NA, NA, "2016-02-04", NA)
)

ui <- fluidPage(
timevisOutput("timeline")
)

server <- function(input, output, session) {
output$timeline <- renderTimevis({
timevis(data, options = list(verticalScroll = TRUE , orientation = 'top'))
})
}

shinyApp(ui = ui, server = server)`

Thanks,
Luqi

node colours not working

i am trying to recreate this example and cant figure out how to add the different colours

data <- data.frame(
  id      = 1:4,
  content = c("Item one"  , "Item two"  ,"Ranged item", "Item four"),
  start   = c("2016-01-10", "2016-01-11", "2016-01-20", "2016-02-14 15:00:00"),
  end     = c(NA          ,           NA, "2016-02-04", NA)
)

timevis(data)

you have in the vignette

but i get this:

image

devtools::session_info()
Session info ----------------------------------------------------------------
 setting  value                       
 version  R version 3.3.2 (2016-10-31)
 system   x86_64, darwin13.4.0        
 ui       RStudio (1.1.331)           
 language (EN)                        
 collate  en_US.UTF-8                 
 tz       America/New_York            
 date     2017-10-03                  

Packages --------------------------------------------------------------------
 package    * version date       source        
 backports    1.1.0   2017-05-22 CRAN (R 3.3.2)
 base       * 3.3.2   2016-10-31 local         
 datasets   * 3.3.2   2016-10-31 local         
 devtools     1.13.3  2017-08-02 cran (@1.13.3)
 digest       0.6.12  2017-01-27 cran (@0.6.12)
 evaluate     0.10.1  2017-06-24 cran (@0.10.1)
 graphics   * 3.3.2   2016-10-31 local         
 grDevices  * 3.3.2   2016-10-31 local         
 htmltools    0.3.6   2017-04-28 CRAN (R 3.3.2)
 httpuv       1.3.5   2017-07-04 cran (@1.3.5) 
 knitr        1.17    2017-08-10 cran (@1.17)  
 magrittr     1.5     2014-11-22 CRAN (R 3.3.0)
 memoise      1.1.0   2017-09-07 local         
 methods    * 3.3.2   2016-10-31 local         
 mime         0.5     2016-07-07 CRAN (R 3.3.0)
 R6           2.2.2   2017-06-17 cran (@2.2.2) 
 Rcpp         0.12.12 2017-07-15 CRAN (R 3.3.2)
 rmarkdown    1.6     2017-06-15 CRAN (R 3.3.2)
 rprojroot    1.2     2017-01-16 CRAN (R 3.3.2)
 rstudioapi   0.7     2017-09-07 cran (@0.7)   
 shiny        1.0.5   2017-08-23 cran (@1.0.5) 
 stats      * 3.3.2   2016-10-31 local         
 stringi      1.1.5   2017-04-07 CRAN (R 3.3.2)
 stringr      1.2.0   2017-02-18 CRAN (R 3.3.2)
 timevis    * 0.4     2016-09-17 CRAN (R 3.3.0)
 tools        3.3.2   2016-10-31 local         
 utils      * 3.3.2   2016-10-31 local         
 withr        2.0.0   2017-07-28 CRAN (R 3.3.2)
 xtable       1.8-2   2016-02-05 CRAN (R 3.3.0)
 yaml         2.1.14  2016-11-12 cran (@2.1.14)

timevis can leak (potentially) private information

the entire dataframe provided as the 'data' argument to timevis (same for 'groups' argument) ends up in the resulting HTML file, including columns not actually used by timevis/vis.js's Timeline. if the user has passed an existing dataframe, this can cause information leakage.

Upgrade to latest visjs Timeline

Currently timevis uses visjs v4.16.1

It'd be nice to update to the most up to date version because they have new features. But there are some issues (and perhaps more, everything needs to be tested thoroughly to make sure nothing breaks):

  • When setting options(editable = TRUE), editing items now requires double clicking instead of single clicks, which is a bug. It should still be only a single click to initiate an edit (this is a bug on visjs: almende/vis#3852)
  • Dates with times don't work in RStudio (need to add 'T' between the date and the time)
  • Times are auto converted to the current user timezone, which results in UI that looks a bit wrong (this is a bug on visjs: almende/vis#3851)

Hot Timevis remove all items at the same time?

thanks for daattali's great job, I am using timevis to visualize a time series of user behaviour. However, I fail to find the function to remove all items at the same time on the timevis, just like leaflet::removeMarker, to store the items list is so redundant for this case.

Now, my shiny app query twice user behaviour will be a little bit weird because I don't know how to clear previous query results.

formatTimevisDF<- function(df,input, output,session){
  for ( i in seq(df %>% nrow())){
    tmp = df[i,]
    print(tmp)
    # timeline formatting
    timevis::addItem("timeline",
                     list(id = tmp$orderid,
                          content = tmp$context,
                          group = substr(as.character(tmp$starttime),1,10),
                          start = paste0(as.character(Sys.Date())," ",substr(as.character(tmp$starttime),12,20)),
                          end = paste0(as.character(Sys.Date())," ",substr(as.character(tmp$endtime),12,20))
                     ))
  }
}

jquery and bootstrap dependencies loaded when not needed

In timevis() jquery and bootstrap are loaded into the head section (line 346-349 & 359) - however that conflicts with my site and I would like to be able to not load it and set 'dependencies = NULL'. I'm thinking that it would only take an extra argument to the timevis() function like:

timevis <- function(data, groups, showZoom = TRUE, zoomFactor = 0.5, fit = TRUE, options, width = NULL, height = NULL, elementId = NULL, loaddependencies = TRUE)

Line 346:
deps <- if(loaddependencies) {list( rmarkdown::html_dependency_jquery(), rmarkdown::html_dependency_bootstrap("default") )} else NULL

Then it don't load the default jquery and bootstrap libraries.

More detailed options for 'editable'

Is it possible to have the possibility to change the group of an item, while disabling the possibility of changing the start / end times? The item should still be deletable.

I mean something like here, where you can edit the 'editable' option in a detailed way:
http://visjs.org/examples/timeline/editing/individualEditableItems.html

var items = new vis.DataSet([
{id: 1, content: 'Editable', editable: true, start: '2010-08-23', group: 1},
{id: 2, content: 'Editable', editable: true, start: '2010-08-23T23:00:00', group: 2},
{id: 3, content: 'Read-only', editable: false, start: '2010-08-24T16:00:00', group: 1},
{id: 4, content: 'Read-only', editable: false, start: '2010-08-26', end: '2010-09-02', group: 2},
{id: 5, content: 'Edit Time Only', editable: { updateTime: true }, start: '2010-08-28', group: 1},
{id: 6, content: 'Edit Group Only', editable: { updateGroup: true }, start: '2010-08-29', group: 2},
{id: 7, content: 'Remove Only', editable: { remove: true }, start: '2010-08-31', end: '2010-09-03', group: 1},
{id: 8, content: 'Default', start: '2010-09-04T12:00:00', group: 2}
]);

Can't use tibbles

Trying to use a tibble versus a data.frame causes errors:

library(timevis) # daattali/timevis
library(tibble)
data <- tibble::data_frame(
  id      = 1:4,
  content = c("Item one"  , "Item two"  ,"Ranged item", "Item four"),
  start   = c("2016-01-10", "2016-01-11", "2016-01-20", "2016-02-14 15:00:00"),
  end     = c(NA          ,           NA, "2016-02-04", NA)
)
timevis(data)
#> Error: Can't use matrix or array for column indexing

Created on 2018-04-02 by the reprex package (v0.2.0).

I think just adding a is.tibble then as.data.frame may help on line:

if (!is.data.frame(df)) {
which occurs because this returns TRUE because of tibble inheritance

You can also just do a simple:

if (is.data.frame(df)) {
    df = as.data.frame(df)
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.