Skip to content

Commit

Permalink
updated documentation of the 'checkCallback' parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
stla committed Sep 22, 2020
1 parent a52f01d commit 374d7fc
Show file tree
Hide file tree
Showing 3 changed files with 228 additions and 4 deletions.
6 changes: 4 additions & 2 deletions R/jstree.R
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,10 @@ NULL
#' to create/rename/delete/cut/copy/paste nodes, or a list of options; see
#' the \href{https://www.jstree.com/api/}{jsTree API documentation} for the
#' possible options
#' @param checkCallback a JavaScript function; see the example where it is used
#' to define restrictions on the drag-and-drop behavior
#' @param checkCallback either \code{TRUE} to allow to perform some actions
#' such as creating a new node, or a JavaScript function; see the example
#' where this option is used to define restrictions on the drag-and-drop
#' behavior
#' @param grid list of settings for the grid; see the second example, the
#' \link[jsTreeR:jstreeOutput]{Shiny example}, and
#' \href{https://github.com/deitch/jstree-grid/#options}{github.com/deitch/jstree-grid}
Expand Down
220 changes: 220 additions & 0 deletions inst/essais/essai_shiny_grid_02.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
library(jsTreeR)
library(shiny)

js <- HTML(
"function addNode() {",
" var tree = $('#jstree').jstree(true);",
" var btn = '<button>test</button>';",
" var node = {text: 'hello', type: 'fruit', data: {price: 1, quantity: btn, cssclass: 'lightorange'}};",
" tree.create_node('Fruits', node);",
"}"
)

nodes <- list(
list(
text = "Fruits",
id = "Fruits",
type = "fruit",
icon = "supertinyicon-transparent-raspberry_pi",
a_attr = list(class = "helvetica"),
children = list(
list(
text = "Apple",
type = "fruit",
data = list(
price = 0.1,
quantity =
as.character(
actionButton(
"restore",
"Restore",
class = "btn-sm",
`data-path` = "/home/fol.der"
)
),
cssclass = "lightorange"
)
),
list(
text = "Banana",
type = "fruit",
data = list(
price = 0.2,
quantity = 31,
cssclass = "lightorange"
)
),
list(
text = "Grapes",
type = "fruit",
data = list(
price = 1.99,
quantity = 34,
cssclass = "lightorange"
)
),
list(
text = "Mango",
type = "fruit",
data = list(
price = 0.5,
quantity = 8,
cssclass = "lightorange"
)
),
list(
text = "Melon",
type = "fruit",
data = list(
price = 0.8,
quantity = 4,
cssclass = "lightorange"
)
),
list(
text = "Pear",
type = "fruit",
data = list(
price = 0.1,
quantity = 30,
cssclass = "lightorange"
)
),
list(
text = "Strawberry",
type = "fruit",
data = list(
price = 0.15,
quantity = 32,
cssclass = "lightorange"
)
)
),
state = list(
opened = TRUE
)
),
list(
text = "Vegetables",
type = "vegetable",
icon = "supertinyicon-transparent-vegetarian",
a_attr = list(class = "helvetica"),
children = list(
list(
text = "Aubergine",
type = "vegetable",
data = list(
price = 0.5,
quantity = 8,
cssclass = "lightgreen"
)
),
list(
text = "Broccoli",
type = "vegetable",
data = list(
price = 0.4,
quantity = 22,
cssclass = "lightgreen"
)
),
list(
text = "Carrot",
type = "vegetable",
data = list(
price = 0.1,
quantity = 32,
cssclass = "lightgreen"
)
),
list(
text = "Cauliflower",
type = "vegetable",
data = list(
price = 0.45,
quantity = 18,
cssclass = "lightgreen"
)
),
list(
text = "Potato",
type = "vegetable",
data = list(
price = 0.2,
quantity = 38,
cssclass = "lightgreen"
)
)
)
)
)

grid <- list(
columns = list(
list(
width = 200,
header = "Product",
headerClass = "bolditalic yellow centered",
wideValueClass = "cssclass"
),
list(
width = 150,
value = "price",
header = "Price",
wideValueClass = "cssclass",
headerClass = "bolditalic yellow centered",
wideCellClass = "centered"
),
list(
width = 150,
value = "quantity",
header = "Quantity",
wideValueClass = "cssclass",
headerClass = "bolditalic yellow centered",
wideCellClass = "centered"
)
),
width = 600
)

types <- list(
fruit = list(
a_attr = list(
class = "lightorange"
),
icon = "supertinyicon-transparent-symantec"
),
vegetable = list(
a_attr = list(
class = "lightgreen"
),
icon = "supertinyicon-transparent-symantec"
)
)

ui <- fluidPage(
tags$head(
tags$script(js),
tags$style(
HTML(c(
"button[id^=restore] {padding: 0 10px;}",
".lightorange {background-color: #fed8b1;}",
".lightgreen {background-color: #98ff98;}",
".bolditalic {font-weight: bold; font-style: italic; font-size: large;}",
".yellow {background-color: yellow !important;}",
".centered {text-align: center; font-family: cursive;}",
".helvetica {font-weight: 700; font-family: Helvetica; font-size: larger;}"
))
)
),
titlePanel("jsTree grid"),
actionButton("add", "Add node", onclick = "addNode();"),
jstreeOutput("jstree")
)

server <- function(input, output){
output[["jstree"]] <-
renderJstree(jstree(nodes, grid = grid, types = types, checkCallback = TRUE))
}

shinyApp(ui, server)
6 changes: 4 additions & 2 deletions man/jstree.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 374d7fc

Please sign in to comment.