Skip to content

Commit

Permalink
Transform the input list.
Browse files Browse the repository at this point in the history
Closes #5.
  • Loading branch information
trestletech committed Nov 20, 2014
1 parent d656647 commit 9930b98
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
12 changes: 12 additions & 0 deletions NEWS
@@ -0,0 +1,12 @@

v 0.2.0
--------------------------------------------------------------------------------

- BREAKING CHANGE: Model the `input$list`-style lists after the list structure
provided to `renderTree`, meaning that they are now a simple are list with the
same `st`- prefixed attributes. See `inst/examples/05-structure`.

v 0.1.0
--------------------------------------------------------------------------------

- Initial Release
22 changes: 19 additions & 3 deletions R/init.R
Expand Up @@ -13,8 +13,7 @@ initResourcePaths <- function() {
# Parse incoming shinyTable input from the client
.onLoad <- function(libname, pkgname){
shiny::registerInputHandler("shinyTable", function(val, shinysession, name){
val

jsonToAttr(val)
})
}

Expand All @@ -25,13 +24,30 @@ jsonToAttr <- function(json){
# This is a top-level list, not a node.
for (i in 1:length(json)){
ret[[json[[i]]$text]] <- jsonToAttr(json[[i]])
ret[[json[[i]]$text]] <- supplementAttr(ret[[json[[i]]$text]], json[[i]])
}
return(ret)
}

if (length(json$children) > 0){
return(jsonToAttr(json[["children"]]))
} else {
return("")
ret <- 0
ret <- supplementAttr(ret, json)
return(ret)
}
}

supplementAttr <- function(ret, json){
# Only add attributes if non-default
if (json$state$selected != FALSE){
attr(ret, "stselected") <- json$state$selected
}
if (json$state$disabled != FALSE){
attr(ret, "stdisabled") <- json$state$disabled
}
if (json$state$opened != FALSE){
attr(ret, "stopened") <- json$state$opened
}
ret
}

0 comments on commit 9930b98

Please sign in to comment.