rpart treeR/visTreeModule.R
visNetwork-treeModule.RdNeeded packages : shiny, rpart, colourpicker, shinyWidgets, sparkline
visTreeModuleServer(
input,
output,
session,
data,
tooltip_data = NULL,
tooltipColumns = "",
main = "",
submain = "",
footer = "",
direction = "UD",
fallenLeaves = FALSE,
rules = TRUE,
simplifyRules = TRUE,
shapeVar = "dot",
shapeY = "square",
colorVar = NULL,
colorY = NULL,
colorEdges = "#8181F7",
nodesFontSize = 16,
edgesFontSize = 14,
edgesFontAlign = "horizontal",
legend = TRUE,
legendNodesSize = 22,
legendFontSize = 16,
legendWidth = 0.1,
legendNcol = 1,
legendPosition = "left",
nodesPopSize = FALSE,
minNodeSize = 15,
maxNodeSize = 30,
highlightNearest = list(enabled = TRUE, degree = list(from = 50000, to = 0), hover =
FALSE, algorithm = "hierarchical"),
collapse = list(enabled = TRUE, fit = TRUE, resetHighlight = TRUE, clusterOptions =
list(fixed = TRUE, physics = FALSE)),
updateShape = TRUE,
tooltipDelay = 500,
digits = 3,
height = 650,
width = "100%",
export = TRUE
)
visTreeModuleUI(
id,
rpartParams = TRUE,
visTreeParams = TRUE,
quitButton = FALSE
)list shiny input
list, shiny output
list, shiny session
reactive, a data.frame or a rpart result. Must be a reactive object
reactive, a data.frame. if data is a rpart,
data.frame used to build tree in order to plot sparkline
numeric, indice of columns used in tooltip. All by default.
So, we add boxplot / pie focus on sub-population vs all population using sparkline package. NULL to disable.
Title. See visNetwork
Subtitle. See visNetwork
Footer. See visNetwork
character, The direction of the hierarchical layout.
The available options are: UD, DU, LR, RL. To simplify:
up-down, down-up, left-right, right-left. Default UD. See visHierarchicalLayout
boolean leaf nodes at the bottom of the graph ? Default to FALSE
boolean, add rules in tooltips ? Default to TRUE
boolean, simplify rules writing
character, shape for variables nodes See visNodes
character, shape for terminal nodes See visNodes
character, colors to use or data.frame To set color of variables. 2 columns :
"variable" names of variables
"color" colors (in hexa). See examples
if classification tree : character colors to use or data.frame 2 columns :
"modality" levels of Y
"color" colors (in hexa)
if regression tree : character, 2 colors (min and max, in hexa)
character, color of edges, in hexa. Default to #8181F7
numeric, size of labels of nodes. Default to 16
numeric, size of labels of edges Default to 14
character, for edges only. Default tp 'horizontal'. Possible options: 'horizontal' (Default),'top','middle','bottom'. See visEdges
boolean, add legend ? Default TRUE. visLegend
numeric, size of nodes in legend. Default to 22
numeric, size of labels of nodes in legend. Default to 16
numeric, legend width, between 0 and 1. Default 0.1
numeric, number of columns in legend. Default 1
character, one of "left" (Default) or "right"
boolean, nodes sizes depends on population ? Default to FALSE
numeric, in case of nodesPopSize, minimum size of a node. Default to 15. Else, nodes size is minNodeSize + maxNodeSize / 2
numeric, in case of nodesPopSize, maximum size of a node. Default to 30. Else, nodes size is minNodeSize + maxNodeSize / 2
list, Highlight nearest nodes. See visOptions
list, collapse or not using double click on a node ? See visOptions
boolean, in case of collapse, udpate cluster node shape as terminal node ? Default to TRUE
numeric, delay for tooltips in millisecond. Default 500
numeric, number of digits. Default to 3
character, default to "600px"
character, default to "100%"
boolean, add export button. Default to TRUE
character id of module, linked to visTreeModuleServer
boolean, add tabs for rpart parameters (in case of data.frame in input)
boolean, add tabs for visTree parameters. Default to TRUE. Force to TRUE if rpartParams
boolean, add a button to quit module and get back network in R ?
See online documentation https://datastorm-open.github.io/visNetwork/
if (FALSE) { # \dontrun{
require(rpart)
# simple module editor on rpart
data <- iris
shiny::shinyApp(ui = shiny::fluidPage(
visTreeModuleUI(id = "id1", rpartParams = FALSE, visTreeParams = FALSE)),
server = function(input, output, session) {
shiny::callModule(visTreeModuleServer, "id1", data = shiny::reactive(rpart(data)))
})
# full module editor on rpart + data.frame for sparkline
data <- iris
shiny::shinyApp(ui = shiny::fluidPage(
visTreeModuleUI(id = "id1", rpartParams = FALSE, visTreeParams = TRUE)),
server = function(input, output, session) {
shiny::callModule(visTreeModuleServer, "id1", data = shiny::reactive(rpart(data)),
tooltip_data = data)
})
# module on data.frame
shiny::shinyApp(ui = shiny::fluidPage(visTreeModuleUI(id = "id1",
rpartParams = TRUE)),
server = function(input, output, session) {
shiny::callModule(visTreeModuleServer, "id1", data = shiny::reactive(data))
})
# multiple modules
shiny::shinyApp(ui =
navbarPage("Menu",shiny::tabPanel(
"tt1",shiny::fluidPage(visTreeModuleUI(id = "id1",
rpartParams = TRUE,
visTreeParams = TRUE))
),
shiny::tabPanel(
"tt2",shiny::fluidPage(visTreeModuleUI(id = "id2",
rpartParams = FALSE,
visTreeParams = FALSE)))
),
server = function(input, output, session) {
shiny::callModule(visTreeModuleServer, "id1", data = shiny::reactive(iris))
shiny::callModule(visTreeModuleServer, "id2", data = shiny::reactive(rpart(iris)))
})
} # }