diff --git a/R/LinkAll.R b/R/LinkAll.R index 569479b..42bb24f 100644 --- a/R/LinkAll.R +++ b/R/LinkAll.R @@ -12,15 +12,14 @@ allDepFunction <- function(envir, name.functions) { link <- toutfonc functions.list <- unique(as.character(unlist(c(toutfonc)))) - + Visdata <- list() Nomfun <- functions.list Nomfun <- data.frame(cbind(id = 1:length(Nomfun), label = Nomfun)) - - - func.link <- sort(unique(c(as.character(link[, 1]), as.character(link[, 2])))) - func.nom <- sort(unique(as.character(Nomfun[, 2]))) + + # func.link <- sort(unique(c(as.character(link[, 1]), as.character(link[, 2])))) + # func.nom <- sort(unique(as.character(Nomfun[, 2]))) if (!is.null(link)) { fromto <- matrix(0, ncol = dim(link)[2], nrow = dim(link)[1]) diff --git a/R/VisGraphAuto.R b/R/VisGraphAuto.R index 88e224c..d934bfa 100644 --- a/R/VisGraphAuto.R +++ b/R/VisGraphAuto.R @@ -174,6 +174,9 @@ prepareToVis <- function(link, functions.list = NULL) { #' dep <- funDependencies('package:ibr','iterchoiceS1') #' plot(dep) #' +#' # size +#' plot(dep, height = "800px", width = "100%") +#' #' @export funDependencies <- function(envir, name.function) { visdata <- prepareToVis(linksForOne(envir, name.function)) @@ -190,6 +193,9 @@ funDependencies <- function(envir, name.function) { #' dep <- envirDependencies('package:ibr') #' plot(dep) #' +#' # size +#' plot(dep, height = "800px", width = "100%") +#' #' @export envirDependencies <- function(envir) { name.functions <- allFunctionEnv(envir) @@ -234,18 +240,25 @@ VisFunsmatrice <- function(Mat) { #' Plot network for dependenciesGraphs object. Using visNetwork package. #' #' @param object : dependenciesGraphs object. +#' @param width : Width (optional, defaults to automatic sizing) +#' @param height : Height (optional, defaults to automatic sizing) #' #' @examples #' #' dep <- funDependencies('package:ibr','iterchoiceS1') #' plot(dep) #' +#' # size +#' plot(dep, height = "800px", width = "100%") +#' #' @export #' @method plot dependenciesGraphs -plot.dependenciesGraphs <- function(object, block = FALSE) { - visNetwork(object[[1]], object[[2]]) %>% visEdges(arrows = "from") %>% visOptions(highlightNearest = TRUE, nodesIdSelection = TRUE) %>% - visInteraction(dragNodes = !block) %>% visPhysics(solver = "repulsion", stabilization = list(enabled = FALSE, iterations = 5000, - onlyDynamicEdges = FALSE)) +plot.dependenciesGraphs <- function(object, block = FALSE, width = NULL, height = NULL) { + visNetwork(object[[1]], object[[2]], width = width, height = height) %>% + visEdges(arrows = "from") %>% + visOptions(highlightNearest = TRUE, nodesIdSelection = TRUE) %>% + visInteraction(dragNodes = !block) %>% + visPhysics(solver = "repulsion", stabilization = list(enabled = FALSE, iterations = 5000, onlyDynamicEdges = FALSE)) } diff --git a/inst/Shiny/SERVER.R b/inst/Shiny/SERVER.R index bceab74..a04f89b 100644 --- a/inst/Shiny/SERVER.R +++ b/inst/Shiny/SERVER.R @@ -32,16 +32,27 @@ shinyServer(function(input, output, session) { optionsDT_fixe$drawCallback <- I("function( settings ) {document.getElementById('tabledep').style.width = '400px';}") ## Output first graph - df <- data.frame(Function = func, Import = nb.func.master, `Imported by` = nb.func.slave) + df <- data.frame(Package = func, Import = nb.func.master, `Imported by` = nb.func.slave) output$tabledep <- renderDataTable({ df }, options = optionsDT_fixe) - # print(data) + output$main_plot <- renderVisNetwork({ - plot(data, block = TRUE) + net <- plot(data, block = TRUE) + + # add legend + data_legend <- unique(data2$fromto[, c("title", "color")]) + data_legend$label <- gsub("
", "", data_legend$title, fixed = TRUE) + data_legend$label <- gsub("
", "", data_legend$label, fixed = TRUE) + data_legend$title <- NULL + data_legend$arrows <- "to" + + net %>% + visLegend(addEdges = data_legend, useGroups = FALSE, width = 0.1) + }) curentd1 <<- data output$titledatatabel <- renderText({ diff --git a/inst/Shiny/UI.R b/inst/Shiny/UI.R index 7fec860..57bfca2 100644 --- a/inst/Shiny/UI.R +++ b/inst/Shiny/UI.R @@ -1,115 +1,119 @@ dashboardPage( dashboardHeader(title = "DependenciesGraphs"), - dashboardSidebar( disable = TRUE), + dashboardSidebar(sidebarMenu(id = "Tabsetpan", + menuItem("Packages", tabName = "Packages", icon = icon("dashboard")), + conditionalPanel(condition = "input.Tabsetpan === 'Packages'", + selectInput('packages', "Package(s) :", choices = installed.packages()[,1], multiple = T, width = "100%"), + div(actionButton("GOPackage", "Go !",icon = icon("line-chart")), align = "center") + ), + menuItem("Functions", tabName = "Functions", icon = icon("th")), + conditionalPanel(condition = "input.Tabsetpan === 'Functions'", + selectInput('package', "Package : ", choices = installed.packages()[,1], multiple = FALSE, width = "100%"), + div(actionButton("GOFunc2", "Go !",icon = icon("line-chart")), align = "center") + ), + menuItem("Custom", tabName = "Custom", icon = icon("th")) + + )), dashboardBody( # Boxes need to be put in a row (or column) tags$head(tags$link(rel='stylesheet', type='text/css', href='style.css')), - - tabsetPanel(id = "Tabsetpan", title = "Packages exploration", width = "100%", - # The id lets us use input$tabset1 on the server to find the current tab - tabPanel("Packages", - fluidRow( - column(3, div(h3('Package(s) selection :'), align = "center")), - column(6, br(), selectInput('packages', NULL, choices = installed.packages()[,1], multiple = T, width = "100%")), - column(3, br(), div(actionButton("GOPackage", "Launch",icon = icon("line-chart")), align = "center")) - ), - hr(), - - fluidRow( - box( - solidHeader = TRUE, collapsible = TRUE, title = "Dependencies between package(s)", - status = "primary", - visNetworkOutput("main_plot", width = "100%",height = "750px"), - br() - ,width = 12 - ), - box( - solidHeader = TRUE, collapsible = TRUE, title = "Informations", - status = "primary", - div( - dataTableOutput("tabledep"), - uiOutput("Groupebutton"), - align="center" - ), - width=12) - ) - + tabItems( + # First tab content + tabItem(tabName = "Packages", + # fluidRow( + # column(3, div(h3('Package(s) selection :'), align = "center")), + # column(6, br(), selectInput('packages', NULL, choices = installed.packages()[,1], multiple = T, width = "100%")), + # column(3, br(), div(actionButton("GOPackage", "Launch",icon = icon("line-chart")), align = "center")) + # ), + # hr(), + + fluidRow( + box( + solidHeader = TRUE, collapsible = TRUE, title = "Dependencies between package(s)", + status = "primary", + visNetworkOutput("main_plot", width = "100%",height = "750px"), + br() + ,width = 12 ), - tabPanel("Functions", - - fluidRow( - column(4, div(h3('Package :'), align = "center")), - column(4, br(), selectInput('package', NULL, choices = installed.packages()[,1], multiple = FALSE, width = "100%")), - column(4, br(), div(actionButton("GOFunc2", "Launch",icon = icon("line-chart")), align = "center")) - ), - hr(), - - fluidRow( - box( - solidHeader = TRUE, collapsible = TRUE, title = "Dependencies between functions", - status = "primary", - div(h4(textOutput("zoomin")), align = "center"), - visNetworkOutput("main_plot1", width = "100%",height = "750px"), - br() - ,width = 12 - ), - box( - solidHeader = TRUE, collapsible = TRUE, title = "Informations", - status = "primary", - div( - # h4(textOutput("info")), - dataTableOutput("datatable2") - ,align="center" - ), - width=12) - ), - - fluidRow( - box( - uiOutput("help"),width = 12 - ) - ) + box( + solidHeader = TRUE, collapsible = TRUE, title = "Informations", + status = "primary", + div( + dataTableOutput("tabledep"), + uiOutput("Groupebutton"), + align="center" + ), + width=12) + ) + + ), + tabItem(tabName = "Functions", + fluidRow( + box( + solidHeader = TRUE, collapsible = TRUE, title = "Dependencies between functions", + status = "primary", + div(h4(textOutput("zoomin")), align = "center"), + visNetworkOutput("main_plot1", width = "100%",height = "750px"), + br() + ,width = 12 ), - # tabPanel("Script", - # - # - # fluidRow( - # box( - # fileInput('file1', 'Choose R File', - # accept=NULL), - # visNetworkOutput("plotscript", width = "100%",height = "700px") - # ,width = 12) - # ) - # ), - - tabPanel("Custom", - - - fluidRow( - box( - fluidRow( - column(width=4, - selectizeInput(inputId = "packageslist" , "Package(s) :", choices = installed.packages()[,1], multiple = TRUE) - ), - column(width=2, - br(), div(actionButton("chargedf", "Find functions", style = "padding: 8px 20px 8px 20px;"),align="center") - ), - column(width=4, - selectizeInput(inputId = "functionlist" , "Function(s) :", choices = NULL, multiple = TRUE) - ), - column(width=2, - br(), div(actionButton("makegraph", "Make graph", style = "padding: 8px 20px 8px 20px;"),align = "center") - ) - ), - - hr(), - visNetworkOutput("chossefunctionplot", width = "100%",height = "750px"), - br(), - width = 12) - ) + box( + solidHeader = TRUE, collapsible = TRUE, title = "Informations", + status = "primary", + div( + # h4(textOutput("info")), + dataTableOutput("datatable2") + ,align="center" + ), + width=12) + ), + + fluidRow( + box( + uiOutput("help"),width = 12 ) - - + ) + ), + # tabPanel("Script", + # + # + # fluidRow( + # box( + # fileInput('file1', 'Choose R File', + # accept=NULL), + # visNetworkOutput("plotscript", width = "100%",height = "700px") + # ,width = 12) + # ) + # ), + + tabItem(tabName = "Custom", + + + fluidRow( + box( + fluidRow( + column(width=4, + selectizeInput(inputId = "packageslist" , "Package(s) :", choices = installed.packages()[,1], multiple = TRUE) + ), + column(width=2, + br(), div(actionButton("chargedf", "Find functions", style = "padding: 8px 20px 8px 20px;"),align="center") + ), + column(width=4, + selectizeInput(inputId = "functionlist" , "Function(s) :", choices = NULL, multiple = TRUE) + ), + column(width=2, + br(), div(actionButton("makegraph", "Make graph", style = "padding: 8px 20px 8px 20px;"),align = "center") + ) + ), + + hr(), + visNetworkOutput("chossefunctionplot", width = "100%",height = "750px"), + br(), + width = 12) + ) + ) + + ) ) ) diff --git a/inst/Shiny/temp.html b/inst/Shiny/temp.html index 9c2fc91..a73c173 100644 --- a/inst/Shiny/temp.html +++ b/inst/Shiny/temp.html @@ -1,195 +1,80 @@ -foodweb | R Documentation |
simOptions | R Documentation |
foodweb
is applied to a group of functions (e.g. all those in a workspace); it produces a graphical display showing the hierarchy of which functions call which other ones. This is handy, for instance, when you have a great morass of functions in a workspace, and want to figure out which ones are meant to be called directly. callers.of(funs)
and callees.of(funs)
show which functions directly call, or are called directly by, funs
.
+
The function readAntares
stores in its output the options used
+to read some data (path of the study, area list, link list, start date,
+etc.).
-foodweb( funs, where=1, charlim=80, prune=character(0), rprune, ancestors=TRUE, descendents=TRUE, plotting =TRUE, plotmath=FALSE, generics=c( "c","print","plot", "["), lwd=0.5, xblank=0.18, border="transparent", boxcolor="white", textcolor="black", color.lines=TRUE, highlight="red", ...) -## S3 method for class 'foodweb' -plot(x, textcolor, boxcolor, xblank, border, textargs = list(), use.centres = TRUE, color.lines = TRUE, poly.args = list(), expand.xbox = 1.05, expand.ybox = expand.xbox * 1.2, plotmath = FALSE, cex=par( "cex"), ...) # plot.foodweb -callers.of( funs, fw=foodweb( plotting=FALSE)) -callees.of( funs, fw=foodweb( plotting=FALSE)) +simOptions(x = NULL)
funs |
+|
x |
- character vector OR (in |
where |
-
- position(s) on search path, or an environment, or a list of environments - |
charlim |
-
- controls maximum number of characters per horizontal line of plot - |
prune |
-
- character vector. If omitted, all |
rprune |
-
- regexpr version of |
ancestors |
-
- show ancestors of |
descendents |
-
- show descendents of |
plotting |
-
- graphical display? - |
plotmath |
-
- leave alone - |
generics |
-
- calls TO functions in |
lwd |
-
- see |
xblank |
-
- leave alone - |
border |
-
- border around name of each object ( |
boxcolor |
-
- background colour of each object's text box - |
textcolor |
-
- of each object - |
color.lines |
-
- will linking lines be coloured according to the level they originate at? - |
highlight |
-
- seemingly not used - |
cex |
-
- text size (see "cex" in |
... |
-
- passed to |
textargs |
-
- not currently used - |
use.centres |
-
- where to start/end linking lines. |
expand.xbox |
-
- how much horizontally bigger to make boxes relative to text? - |
expand.ybox |
-
- how much vertically bigger to ditto? - |
poly.args |
-
- other args to |
fw |
-
- an object of class |
x |
-
- a foodweb (as an argument to object of class |
The main value is in the graphical display. At the top ("level 0"), functions which don't call any others, and aren't called by any others, are shown without any linking lines. Functions which do call others, but aren't called themselves, appear on the next layer ("level 1"), with lines linking them to functions at other levels. Functions called only by level 1 functions appear next, at level 2, and so on. Functions which call each other will always appear on the same level, linked by a bent double arrow above them. The colour of a linking line shows what level of the hierarchy it came from. -
-foodweb
makes some effort to arrange the functions on the display to keep the number of crossing lines low, but this is a hard problem! Judicious use of prune
will help keep the display manageable. Perhaps counterintuitively, any functions NOT linked to those in prune
(which all will be, by default) will be pruned from the display.
-
foodweb
tries to catch names of functions that are stored as text, and it will pick up e.g. glm
in do.call( "glm", glm.args)
. There are limits to this, of course (?methods?).
+
simOptions
extracts these options from an object of class
+antaresTable
or antaresOutput
. It can be useful when working on
+multiple simulations, either to check how some object has been created or to
+use it in some functions like getAreas
or
+getLinks
The argument list may be somewhat daunting, but the only ones normally used are funs
, where
, and prune
. Also, to get a readable display, you may need to reduce cex
and/or charlim
. A number of the less-obvious arguments are set by other functions which rely on plot.foodweb
to do their display work. Several may disappear in future versions.
-
If the display from foodweb
is unclear, try foodweb( .Last.value, cex=<<something below 1>>, charlim=<<something probably less than 100>>)
. This works because foodweb
will also accept a foodweb
-class object as its argument. You can also assign the result of foodweb
to a variable, which is useful if you expect to do a lot of tinkering with the display, or to inspect the who-calls-whom matrix by hand.
-
callers.of
and callees.of
process the output of foodweb
, looking for immediate dependencies only. The second argument will call foodweb
by default, so it may be more efficient to call foodweb
first and assign the result to a variable.
+
If the parameter of the function is NULL
, it returns the default
+simulation options, that is the options set by setSimulationPath
+the last time it was run.
foodweb
returns an object of (S3) class foodweb
. This has three components:
-
funmat |
-
- a matrix of 0s and 1s showing what (row) calls what (column). The |
x |
-
- shows the x-axis location of the centre of each function's name in the display, in |
level |
-
- shows the y-axis location of the centre of each function's name in the display, in |
Apart from graphical annotation, the main useful thing is funmat
, which can be used to work out the "pecking order" and e.g. which functions directly call a given function. callers.of
and callees.of
return a character vector of function names.
+
list of options used to read the data contained in an object or the last
+simulation options read by setSimulationPath
if x
is
+NULL
-foodweb( ) # functions in .GlobalEnv -foodweb( where="package:mvbutils", cex=0.4, charlim=60) # yikes! -foodweb( c( find.funs("package:mvbutils"), "paste")) -# functions in .GlobalEnv, and "paste" -foodweb( find.funs("package:mvbutils"), prune="paste") -# only those parts of the tree connected to "paste"; -# NB that funs <- unique( c( funs, prune)) inside "foodweb" -foodweb( where="package:mvbutils", rprune="aste") -# doesn't include "paste" as it's not in "mvbutils", and rprune doesn't augment funs -foodweb( where="package:mvbutils", rprune="name") # does work -foodweb( where=asNamespace( "mvbutils")) # secret stuff -fw <- foodweb( where="package:mvbutils") -fw$funmat # a big matrix -callers.of( "mlocal", fw) -callees.of( find.funs() %matching% "name", fw) +## Not run: + setSimulationPath(study1) + + simOptions() # returns the options for study 1 + + data <- readAntares() + + # Choose a different study + setSimulationPath(study2) + + simOptions() # returns the options for study 2 + + getAreas() # returns the areas of the secund study + getAreas(opts = simOptions(data)) # returns the areas of the first study + + +## End(Not run) +