I am using the Timevis package to create a timeline in R/Shiny. I would like to set specific editability options for individual items. Some items should be able to move between groups (but not in time), and some items should not be editable at all. I did find this previous question: Setting editable options in Timevis when using R/Shiny?, but it does not mention how to set the options for individual items.
At https://search.r-project.org/CRAN/refmans/timevis/html/timevis.html I found that the underlying Javascript options can be set using the htmlwidgets::JS() command. Using this command I can set the options for the entire timeline as follows:
server <- function(input, output, session)
{
# render timeline
output$timeline <- renderTimevis({
tv <- timevis( data = timevisData, groups = timevisDataGroups, options=list(editable = htmlwidgets::JS("{updateGroup: true, updateTime: false }")))
})
timevisDataGroups <- data.frame(id=c("group 1", "group 2"),
content = c("Group 1", "Group 2")
)
timevisData <- data.frame(id = 1:2,
content = c("name 1", "name 2"),
start = c("2022-01-01", "2022-01-05"),
end = c("2022-01-03", "2022-01-06"),
group = c("group 1", "group 2"),
type = c("range", "range"))
}
However, this does not allow me to distinguish between different items. I tried to set the options for individual items as follows:
server <- function(input, output, session)
{
# render timeline
output$timeline <- renderTimevis({
tv <- timevis( data = timevisData, groups = timevisDataGroups, options=list(editable = TRUE))
})
timevisDataGroups <- data.frame(id=c("group 1", "group 2"),
content = c("Group 1", "Group 2")
)
timevisData <- data.frame(id = 1:2,
content = c("name 1", "name 2"),
start = c("2022-01-01", "2022-01-05"),
end = c("2022-01-03", "2022-01-06"),
group = c("group 1", "group 2"),
options = c(htmlwidgets::JS("editable: {updateGroup: true, updateTime: false }"), htmlwidgets::JS("editable: {updateGroup: false, updateTime: false }")),
type = c("range", "range"))
}
However, the item specific options do not seem to have any effect.
I was also stuck in a similar problem. I found
addItem
function oftimevis
as an alternative way to create items and add them to an emptytimevis
object.Inspired by your example :
Using
addItem
enables creating an item using a list (and not a data.frame) to specifyremove
,updateGroup
andupdateTime
parameters (seetimeline
javascript documentation: https://visjs.github.io/vis-timeline/docs/timeline/) Withitem["start"] > as.Date("2022-01-04")
rule I made up, it should enable you to move name 1 from one group to another.NB : According to timeline R package documentation, you should be able to add a column named "editable" in the timevisData to specify editable for each item (but without controlling the state of
remove
,updateGroup
andupdateTime
separately) but for some reason it does not work for me. It could be a bug to report.