I have an editable datatable in R shiny with user names and start/end dates. I want to add a second header above the main header, and then add a drop down filter based on the top header. How do I go about adding the top row header and linking it to the datatable?
Code:
library(shiny)
library(shinydashboard)
library(tidyverse)
library(DT)
header <- dashboardHeader(title = "My First App")
sidebar <- dashboardSidebar()
body <- dashboardBody(
tabItems(
tabItem(
tabName = 'User View', class = 'active',
fluidRow(
box(
dataTableOutput('userTable'), width = 6
)
)
)
)
)
ui <- dashboardPage(title = 'User View', header, sidebar, body, skin='blue')
server <- function(input, output, session){
dat <- data.frame(name = c("John","Mary","Mike","JJ","Alex","Frido"), start = c("06/08/2011","08/11/2014","13/07/2000","1/1/2006","4/6/2002","9/8/1999"), end = c("06/08/2011","08/11/2014","13/07/2000","1/1/2006","4/6/2002","9/8/1999"),stringsAsFactors = FALSE)
output$userTable <- renderDataTable({
DT::datatable(isolate(dat),
editable = TRUE,
rownames = FALSE,
options=list(
searching = FALSE,
paging = FALSE
))
})
###Tracking Changes###
rvs <- reactiveValues(
data = NA #dynamic data object
)
observe({
rvs$data <- dat
})
proxy = dataTableProxy('userTable')
observe({
DT::replaceData(proxy, rvs$data, rownames = FALSE, resetPaging = FALSE)
})
observeEvent(input$userTable_cell_edit, {
rvs$data <<- editData(rvs$data, input$userTable_cell_edit, rownames = FALSE)
})
}
shinyApp(ui = ui, server = server)
Current Output:
Desired output: