I have a large data frame and I am trying to construct a string based on groups within the data frame for displaying in shinyTree.
Here is an example of data:
dat <- data.frame("region" = c(paste("region", rep(1:3, each=4))),
"area" = c(paste("area", rep(1:6, each=2))),
"name" = c(paste("name",1:12)))
shinyTree
requires that data is constructed in a string that looks like:
listString <- paste0("list('region 1' = list('area 1' = list('name 1'='', 'name 2'=''),
'area 2' = list('name 3'='', 'name 4'='')),
'region 2' = list('area 3' = list('name 5'='', 'name 6'=''),
'area 4' = list('name 7'='', 'name 8'='')),
'region 3' = list('area 5' = list('name 9'='', 'name 10'=''),
'area 6' = list('name 11'='', 'name 12'='')))")
Is there a way to construct this string using mutate and groups in dplyr? The "list("
elements should be concatenated onto the 1st occurrence of each group.
I have tried nested for
loops and nested lapply()
functions with compiler::cmpfun()
to speed it up, but this is proving to be too slow to construct. My data has 5 "levels" and ~3000 rows, and it takes ~30 seconds to process which is too slow for a shiny application.
Any help would be greatly appreciated.