I have made a timeline using timevis.r in R Shiny. I want to make information appear when a user clicks on an item in the timeline, however I am not sure how to do this. The code I have is this:
library(shiny)
library(timevis)
data <- data.frame(id = 1:10,
content = c("a", "b", "c", "d", "e", "f", "g", "h", "i", "j"),
title = c("A", "B", "C", "D", "E", "F", "G", "H", "I", "J"),
start = c("06/12/2017", "08/12/2017", "21/11/2012", "16/01/2013", "15/03/2013","09/12/2017", "20/12/2017",
"25/11/2012", "01/01/2013", "02/03/2013"),
group = c(1,1,1,2,2,3,4,1,3,3),
location = c("Church Lane", "School Field", "Disco", "School Field","Church Lane", "School Field", "Disco",
"Disco", "Church Lane", "School Field")
grouprs <- data.frame(id = 1:4, content = c("Safety", "Information of concern",
"Complaint", "Other"))
options <- list(min = "01/01/2010" , max ="01/01/2020", zoomMin = 86400000))
names <- as.character( unique(data$location) )
ui <- fluidPage(
theme = "timeline.css",
sidebarLayout(
sidebarPanel(
selectInput( "location", "Location", names ),
),
mainPanel(
tabsetPanel(
tabPanel( "Timeline", h1( "Timeline" ),
textOutput("location"),
timevisOutput( "timeline" )),
tabPanel( "tab2", "Blank tab" ),
textOutput("entry") # trying to get the title of the item to appear here when user clicks on the item
)
)))
server <- function(input, output, session) {
locationData <- reactive({
subdata[subdata$location == as.character(input$location), ] })
output$location <- renderText(input$location)
output$timeline <- renderTimevis({
timevis(locationData(), groups = grouprs, options = options)
})
}
shinyApp(ui = ui, server = server)
I think I need to insert a javascript command but I am not sure where. Could I use tags$script
to do that or would that be stupid? At the moment I would be happy just for something to display when the user selects an item- I think if I had that, I could get the rest of the way with making it the title of the item.
Any help/suggestions/nudges would be very welcome! I am pretty new to R and even newer to javascript.