Prequisites

  • You need to be on BlueSky Statistics 10.1
  • You need very basic Javascript knowledge to create dialogs. Every dialog is a javascript file. There are several sample files that we provide and exercises to get you started.

What Is A Dialog?

  • GUI or a front end for making it easy to perform repeated analysis

Running a logistic model in R involves writing R code that does the following

  • Creates the model
  • Summarize the model
  • Display the coefficients
  • See the analysis of deviance
  • Display pseudo rsquared statistics
  • Display odds ratio
  • See the formula
  • Plot the residuals

There’s a lot of code to write

require(MASS);
require(pscl);
require(equatiomatic)
require(textutils)
#Builds a logistic model 
Logistic1= glm(Survived ~ Class+Sex+Age, weights=, family =binomial(link='logit'), na.action=na.exclude, 
data=titanic.raw)
#Display theoretical model equation and coefficients
#Display theoretical model
reg_formula = equatiomatic::extract_eq(Logistic1, raw_tex = FALSE,
     wrap = TRUE, intercept = "alpha", ital_vars = FALSE) 
BSkyFormat(reg_formula)
#Display coefficients
reg_equation = equatiomatic::extract_eq(Logistic1, use_coefs = TRUE,
     wrap = TRUE,ital_vars = FALSE, coef_digits = BSkyGetDecimalDigitSetting() )
BSkyFormat(reg_equation)
#Summarizing the model
BSky_Logistic = summary(Logistic1)
BSkyFormat(BSky_Logistic, singleTableOutputHeader="Model Summary")
#Analysis of variance
BSky_anova = anova(Logistic1, test="Chisq")
BSkyFormat(as.data.frame(BSky_anova),singleTableOutputHeader="Analysis of Deviance Table")
BSkyFormat(attr(BSky_anova, "heading"))
#McFadden R2
BSkyFormat( pR2(Logistic1) ,singleTableOutputHeader="McFadden R2")
#odds ratio and 95% confidence interval
BSkyFormat(exp(cbind(OR=coef(Logistic1), confint.glm(Logistic1,level=0.95))),singleTableOutputHeader="Odds ratio(OR) and 95% Confidence interval ")

The Output is not pretty

Advantage of a GUI

  • No code to write
    • Eliminate 100’s -1000s lines of code
  • Nicely formatted output
    • Easy copy/paste into Microsoft Office apps
  • Portable output
    • Easy to save and distribute
    • Reproducibility

Sample Dialog

Use a point and click GUI instead of writing R code for popular analysis

Sample Output

See the nicely formatted output in tables that you can copy and paste into Microsoft Word, Excel…

Reproducibility

See R Code From Output

Not only can you inspect the R code from the output, but you can edit and execute it as well.

What’s Involved In Creating A Dialog?

  1. Write R code
  2. Identify the parameters that get substituted from the dialog/user input
    • Example: In the case of the Logistic Regression dialog above, the following input from the dialog that a user specifies will be substituted dynamically in the R code that the dialog creates
      1. Model name
      2. Independent variables
      3. Dependent variable
      4. Option for plots
  3. Design the dialog
    • Define controls that map to input parameters
      1. Model name = Textbox control
      2. Independent variables = Destination variable list control
      3. Dependent variable = Destination variable list control
      4. Option for plots = Checkbox
  4. Specify how control content get substituted in R code
  5. Run BSkyFormat on all the R objects you want to see nicely formatted output for
  6. Create the JavaScript code for the dialog
  7. Determine where the dialog gets placed
  8. Create help text

1. Base R Code

require(MASS);
require(pscl);
require(equatiomatic)
require(textutils)
#Builds a logistic model 
Logistic1= glm(Survived ~ Class+Sex+Age, weights=, family =binomial(link='logit'), na.action=na.exclude, 
data=titanic.raw)
#Display theoretical model equation and coefficients
#Display theoretical model
reg_formula = equatiomatic::extract_eq(Logistic1, raw_tex = FALSE,
     wrap = TRUE, intercept = "alpha", ital_vars = FALSE) 
BSkyFormat(reg_formula)
#Display coefficients
reg_equation = equatiomatic::extract_eq(Logistic1, use_coefs = TRUE,
     wrap = TRUE,ital_vars = FALSE, coef_digits = BSkyGetDecimalDigitSetting() )
BSkyFormat(reg_equation)
#Summarizing the model
BSky_Logistic = summary(Logistic1)
BSkyFormat(BSky_Logistic, singleTableOutputHeader="Model Summary")
#Analysis of variance
BSky_anova = anova(Logistic1, test="Chisq")
BSkyFormat(as.data.frame(BSky_anova),singleTableOutputHeader="Analysis of Deviance Table")
BSkyFormat(attr(BSky_anova, "heading"))
#McFadden R2
BSkyFormat( pR2(Logistic1) ,singleTableOutputHeader="McFadden R2")
#odds ratio and 95% confidence interval
BSkyFormat(exp(cbind(OR=coef(Logistic1), confint.glm(Logistic1,level=0.95))),singleTableOutputHeader="Odds ratio(OR) and 95% Confidence interval ")
         

2. Parameters That Get Substituted

The parameters that get substituted based on user entry are in BOLD text in the code block below require(MASS);
require(pscl);
require(equatiomatic)
require(textutils)
#Builds a logistic model
Logistic1= glm(Survived ~ Class+Sex+Age, weights=, family =binomial(link=‘logit’), na.action=na.exclude, data=titanic.raw)
#Display theoretical model equation and coefficients
#Display theoretical model
reg_formula = equatiomatic::extract_eq(Logistic1, raw_tex = FALSE, wrap = TRUE, intercept = “alpha”, ital_vars = FALSE)
BSkyFormat(reg_formula)
#Display coefficients
reg_equation = equatiomatic::extract_eq(Logistic1, use_coefs = TRUE, wrap = TRUE,ital_vars = FALSE, coef_digits = BSkyGetDecimalDigitSetting() )
BSkyFormat(reg_equation)
#Summarizing the model
BSky_Logistic = summary(Logistic1)
BSkyFormat(BSky_Logistic, singleTableOutputHeader=“Model Summary”)
#Analysis of variance
BSky_anova = anova(Logistic1, test=“Chisq”)
BSkyFormat(as.data.frame(BSky_anova),singleTableOutputHeader=“Analysis of Deviance Table”)
BSkyFormat(attr(BSky_anova, “heading”))
#McFadden R2
BSkyFormat( pR2(Logistic1) ,singleTableOutputHeader=“McFadden R2”)
#odds ratio and 95% confidence interval
BSkyFormat(exp(cbind(OR=coef(Logistic1), confint.glm(Logistic1,level=0.95))),singleTableOutputHeader=“Odds ratio(OR) and 95% Confidence interval”)

3. Design The Dialog

4. Specify How Control Content Get Substituted In R code

  • Example 1:
  • After substituting
  • Example 2:
  • After substitution

NOTE: See how the string that gets substituted for the dependent variables in logistic regression i.e. Class+Sex+Age is different from the string that gets substituted for the dependent variables in Random Forest i.e. c(‘Class’,‘Sex’,‘Age’) This is important as different R functions will want dependent variables specified in different formats. In a vast majority of the cases, the extraction property associated with the user interface component e.g. variable list, textbox etc described below will give you the flexibility to control how the string gets substituted to meet the needs of the R function you want to execute.

5. Run BSkyFormat On All Objects To Be Displayed

BSkyFormat is a function provided with the BlueSky Statistics application and available in the BlueSky package that generates nicely formatted output for R objects of the following classes. data.frame matrix table ftable List xtabs htest glm lm by lm Anova summary.glm numSummary tapply summary.lm summary.multinorm multinorm polr summary.polr vectors Type help(BSkyFormat) in the BlueSky Statistics R Syntax editor to see additional details and parameters that can be passed to BSkyFormat

require(MASS);
require(pscl);
require(equatiomatic)
require(textutils)
#Builds a logistic model
Logistic1= glm(Survived ~ Class+Sex+Age, weights=, family =binomial(link=‘logit’), na.action=na.exclude, data=titanic.raw)
#Display theoretical model equation and coefficients
#Display theoretical model
reg_formula = equatiomatic::extract_eq(Logistic1, raw_tex = FALSE, wrap = TRUE, intercept = “alpha”, ital_vars = FALSE)
BSkyFormat(reg_formula)
#Display coefficients
reg_equation = equatiomatic::extract_eq(Logistic1, use_coefs = TRUE, wrap = TRUE,ital_vars = FALSE, coef_digits = BSkyGetDecimalDigitSetting() )
BSkyFormat(reg_equation)
#Summarizing the model
BSky_Logistic = summary(Logistic1)
BSkyFormat(BSky_Logistic, singleTableOutputHeader=“Model Summary”)
#Analysis of variance
BSky_anova = anova(Logistic1, test=“Chisq”)
BSkyFormat(as.data.frame(BSky_anova),singleTableOutputHeader=“Analysis of Deviance Table”)
BSkyFormat(attr(BSky_anova, “heading”))
#McFadden R2
BSkyFormat( pR2(Logistic1) ,singleTableOutputHeader=“McFadden R2”)
#odds ratio and 95% confidence interval
BSkyFormat(exp(cbind(OR=coef(Logistic1), confint.glm(Logistic1,level=0.95))),singleTableOutputHeader=“Odds ratio(OR) and 95% Confidence interval”)

Dialog Properties

To extend BlueSky Statistics, you create new dialogs. The dialog is basically javascript code that specifies the following

  • R code generated by the dialog
  • The UI controls that will be used to parameterize the R code

A dialog has the following properties

  • id: Unique id for the dialog (must be unique across all dialogs)
    • E.g.
    id: "sampleDialog1"
  • Label: The title of the dialog
    • E.g.
    label: localization.en.title
  • Split processing: Repeats the analysis for each level of the factor. Typically applies for analysis commands and not data manipulation commands like sort
    • E.g.
    splitProcessing:false
  • Rcode: The R code the dialog generates and executes
    • We use the Squirrelly templating engine to substitute the contents of the user interface controls into the R code. The contents within {{}} indicate the name of the user interface control that will be substituted. More on that later.
    • E.g.
    RCode: `
      paste(c({{selected.independent | safe}}))
      print("{{selected.inputControl | safe}}")
      `
  • modalType: Controls the layout of the dialog: Can be one of
    • Single column All user interface controls are presented in a single column, one below each other

    • Two column All user interface controls are presented in one of 2 columns, one below each other

    • E.g. for single column

    modalType: "one",
    • E.g. for two columns
    modalType: "two",
  • A set of properties namely items, head, left, right, bottom within an object called content that controls the placement of the user interface controls with the head, left column, right column or bottom sections of the dialog.

NOTE: The head, bottom sections are optional.
The items property is only used when modalType: “one”

  • Header: Optionally place controls in a header

  • Bottom: Optionally place controls below the source variable list

  • E.g.To place the control that captures the name of the model on the top of the dialog

  head: [objects.modelname.el.content]
  • E.g.To place the source variable list (to display all the variables in the source dataset) in the left column
  left: [objects.content_var.el.content]
  • E.g.To place the user interface controls to capture the dependent variable list and the independent variable lists in the right most column one below each other
  right: [objects.modelname.el.content, objects.dependent.el.content, objects.independent.el.content]
  • E.g.To place the user interface controls on the bottom of the dialog
  bottom: [objects.modelname.el.content]
  • E.g.To place the user interface controls one below each other in a dialog with a single column layout
  items: [objects.shape1.el.content, objects.shape2.el.content, 
                objects.plotdenfun.el.content]
  • E.g.Example showing the left and right properties laid out within the content object
   const content = {
            left: [objects.content_var.el.content],
            right: [objects.modelname.el.content, objects.dependent.el.content, objects.independent.el.content, objects.generateplotchk.el.content, objects.destination2.el.content]
           
        };
  • name: The name of the dialog displayed in the top level menu. Clicking on the name in the top level menu launches the dialog. The name property needs to be defined within the nav object which in turn is within the content object.
    • E.g.
    nav: { name: localization.en.navigation}
  • Icon: The icon associated with the dialog in the top level menu. The icon property needs to be defined within the nav object which in turn is within the content object.
    • E.g.
    nav: { icon: "icon-logistic_white_comp"}
  • E.g.Example showing the left and right, name and icon properties laid out within the content object
    const content = {
            left: [objects.content_var.el.content],
            right: [objects.modelname.el.content, objects.dependent.el.content, objects.independent.el.content, objects.generateplotchk.el.content, objects.destination2.el.content],
            nav: {
                name: localization.en.navigation,
                icon: "icon-logistic_white_comp",
                modal: config.id
            }
        };
  • datasetRequired: Do you have to have a dataset open in the dataset grid to open a dialog. The default is true. If you have the default set to true and you try and launch a dialog without a dataset open in the grid, an error is displayed.
    • E.g.
    nav: {datasetRequired:true}
  • helpTitle: Title of the Help dialog. The help title property is located within the help object which in turn is in the en object within localization.
    • E.g.
    help: {
    title: "Enter a title here",
    r_help: "help(glm, package=‘stats’)"
    }
  • body: Contents of the Help Dialog. Only simple markup is supported. Supported markup includes bold i.e. <b>BOLD</b> tags, break </br> tags, tags to display code <code></code>, <ul></ul> and <li> and </li> controls
    • E.g.
    body: ‘
    <b>Description</b></br>
    Builds a binary logistic regression model.... <br/>’
  • r_help: This property allows you to specify R code e.g. help(glm, package=‘stats’) to launch R help associated with a R function. The R help associated with the R function displays in a separate browser window. You can only specify a single R function
  • E.g.
  help: {
    r_help: "help(glm, package=‘stats’)"
  }
  • Study sample dialog Sample 1.js in the development folder in the install directory of the BlueSky Statistics application.

  • Perform the following Exercises Exercise 1 Exercise 1a Exercise 1b

Control Properties

Source Variable List Control

  • Displays all the variables in the active dataset
  • You will typically Copy/Move variables from the source variable control to a destination variable or destination variable list control


Source Variable List Control Properties

  • action: Controls whether the contents of the source variable list are copied or moved
    • E.g. to move the variables
    action: "move" 
    • E.g. to copy the variables
    action: "copy" 


Source Variable List Control Sample Code

  content_var: {
    el: new srcVariableList(config, {
      action: "move"
    }) 
  },


Sample Dialogs for Source Variable List Control

  • Look at any of the dialogs under the top level Analysis menu e.g. Analysis > Correlation. Most dialogs will have a source variable list to allow you to select the variables in the dataset to be analyzed.

Source Dataset List Control

  • Displays all the open datasets in the BlueSky Statistics application
  • Copy/Move datasets from the source dataset control to a destination dataset (allows a singe dataset) or dataset list (allows multiple datasets) control


Source Dataset List Control Properties

  • action: Controls whether the datasets in the source dataset list are copied or moved
    • E.g. to move the dataset
    action: "move" 
    • E.g. to copy the dataset
    action: "copy" 


Source Dataset List Control Sample Code

  dataset_var: {
    el: new srcDatasetList(config, {
      action: "move"
    }) 
  },


Sample Dialogs for Source Dataset List Control

  • Under top level navigation Datasets>Merge>Merge

Destination Variable Control

  • You will drag/drop or copy/move variables from the source variable list to a destination variable (allows a single variable only) or destination variable list control (allows one or more variables)
  • You can control/restrict the type of variable being added to the Destination Variable Control
    • Numeric
    • Factor
    • Ordered factor
    • Date
    • String
  • Optionally force the user to select/Drag and Drop a variable into the control (Dialog will not execute until the control is populated by a variable)


Destination Variable Control Properties

  • no: unique id (each control within a dialog must have a unique id). This unique id is used in the R code to substitute the control content

    • E.g.
    no: "independent"
  • label: String displayed above the variable control

    • E.g.
    label:“Independent variable(s)"
  • required: Optionally force the user to enter a value in the variable control. Dialog will not execute unless a user specifies a value. Default is false.

    • E.g.
    required:false
  • filter: Control the types of variables this control can contain

    • E.g. Following allows variables of type numeric, or date (this includes variables of class POSIXct and Date) or logical or factor or ordered factor
    filter: "Numeric|Date|Logical|Ordinal|Nominal|Scale" 
    • E.g. Following allows only numeric
    filter: "Numeric|Scale"  
    • E.g. Following allows only factor
    filter: "Numeric|Nominal"  
    • E.g. Following allows only ordered factor
    filter: "Numeric|Ordinal"  
    • E.g. Following allows only logical
    filter: "Numeric|Logical" 
    • E.g. Following allows character (string)
      filter: "String" 
  • extraction: Control how the variable entered gets substituted in the R code

    • E.g. Following substitutes variables var1, var2.. entered as var1, var2
    extraction: "NoPrefix|UseComma"  
    • E.g. Following substitutes the variable var1, var2.. entered by prefixing the variable by the name of the dataset being analyzed i.e. dataset1$var1, dataset1$var2…
  extraction: "Prefix|UseComma" 
  • E.g. Following prefixes the variable var1, var2 entered by var1 = dataset1$var1, var2 = dataset2$var2… where dataset1 is the name of the dataset being analyzed
  extraction: "CustomFormat" 
  • E.g. Following substitutes the variable var1, var2.. entered by enclosing each variable by quotes and separating by , i.e. ‘var1’, ‘var2’, ‘var3’
  extraction: "NoPrefix|UseComma|Enclosed" 


Destination Variable Control Sample Code

  dependent: {
    el: new dstVariable(config, {
      label: localization.en.dependent,
      no: "dependent",
      filter: "String|Numeric|Logical|Ordinal|Nominal",
      extraction: "NoPrefix|UseComma",
      required: true,
    }),
  },


Sample RCode For Substitution of Destination Variable Selection

  • Reference the value of the no property of the control enclosed in the format required by the Squirrelly templating engine within the R code, see the example below the no property is “dependent”. Note, in the example below the glm function takes a number of parameters, i.e. the modelname, the dependent variable and the independent variables. In this example we are concerned with the dependent variable

    • E.g.
    {{selected.dependent | safe}}
    Rcode:`{{selected.modelname | safe}}= glm({{selected.dependent | safe}} ~ {{selected.independent | safe}}….`


  • E.g. If dependent variable control contains var1, var2, var3, and extraction is set to ‘NoPrefix|UseComma|Enclosed’, see above for extraction details then myVariables = c(‘var1’, ‘var2’, ‘var3’) will be substituted in the example below

  {{selected.dependent | safe}}
Rcode:`myVariables= c({{selected.dependent | safe}}) ….`


Sample Dialogs for Destination Variable Control

  • Look at Model Fitting > Regression > Linear, Basic, you can specify a single dependent variable.

Destination Dataset Control

  • Select or Move or Copy a Dataset from the Source Dataset List to the Destination Dataset Control
  • Optionally force the user to select a Dataset (Dialog will not execute unless a user makes a selection)


Destination Dataset Control Properties

  • no: unique id (each control within a dialog must have a unique id). This unique id is used in the R code to substitute the control content
    • E.g.
    no: "in1"
  • label: String displayed above the Dataset control
    • E.g.
    label: "Select the 1st Dataset"
  • required: Optionally force the user to specify a value in the Dataset control. Dialog will not execute unless a user specifies a value. Default is false.
    • E.g.
    required:false
  • filter: Control the types of entries this control can contain
    • E.g. allows only datasets
    filter: "Dataset" 
  • extraction: Control how the Dataset entered gets substituted in the R code
    • E.g. Following substitutes datasets data1, data2.. entered as data1, data2
    extraction: "NoPrefix|UseComma"  
    • E.g. Following substitutes datasets data1, data2.. entered as “data1”, “data2”
    extraction: "NoPrefix|UseComma|Enclosed" 


Destination Dataset Control Sample Code

  in1: {
    el: new dstVariable(config, {
      label: localization.en.in1,
      no: "in1",
      filter: "Dataset",
      extraction: "UseComma|Enclosed",
      required: true,
    })
  },


Sample RCode For Substitution of Destination Dataset Control Selection

  • Reference the value of the no property of the control enclosed in the format required by the Squirrelly templating engine within the R code, see the example below the value of the no property is “in1”.
    • E.g.
    {{selected.in1 | safe}}
    Rcode:`paste( "{{selected.mergetype | safe}}","(",{{selected.in1 | safe}},",",{{selected.in2 | safe}},",","by = c(",by.text,"),","{{selected.suffix | safe}}",")")`

Sample Dialogs for Destination Dataset Control

  • Under top level navigation Datasets>Merge>Merge

Destination Variable List Control

  • Select a variable from the Source Variable List and copy/move/drag and drop to the Destination Variable List Control
  • Control the type of variable being added to the Destination Variable Control
    • Numeric
    • Factor
    • Ordered factor
    • Date
    • String
  • Optionally force the user to select a variable (Dialog will not execute unless the user makes a selection)


Destination Variable List Control Properties

  • no: unique id (each control within a dialog must have a unique id) This unique id is used in the R code to substitute the control content
    • E.g.
    no: "independent"
  • label: String displayed above the variable control
    • E.g.
    label:"Independent variable(s)"
  • required: Optionally force the user to enter a value in the variable control. Dialog will not execute unless a user specifies a value. Default is false.
    • E.g.
    required:false
  • filter: Control the types of variables this control can contain
    • E.g. Following allows variables of type numeric, or date (this includes variables of class POSIXct and Date) or logical or factor or ordered factor
    filter: "Numeric|Date|Logical|Ordinal|Nominal|Scale" 
    • E.g. Following allows only numeric
    filter: "Numeric|Scale"  
    • E.g. Following allows only factor
    filter: "Numeric|Nominal"  
    • E.g. Following allows only ordered factor
    filter: "Numeric|Ordinal"  
    • E.g. Following allows only logical
    filter: "Numeric|Logical" 
    • E.g. Following allows character (string)
      filter: "String" 
  • extractions: Control how the variable entered gets substituted in the R code
    • E.g. Following substitutes variables var1, var2.. entered as var1, var2
    extraction: "NoPrefix|UseComma"  
    • E.g. Following substitutes variables var1, var2.. entered as var1 + var2
    extraction: "NoPrefix|UsePlus"  
    • E.g. Following substitutes the variable var1, var2.. entered by prefixing the variable by the name of the dataset being analyzed i.e. dataset1$var1, dataset1$var2…
  extraction: "Prefix|UseComma" 
  • E.g. Following prefixes the variable var1, var2 entered by var1 = dataset1$var1, var2 = dataset2$var2… where dataset1 is the name of the dataset being analyzed
  extraction: "CustomFormat" 
  • wrapped: Allows you to wrap the results of the control within another string. For example, just say you want to pass the parameter weights = c(“variable name”) to a function but only when the weights value was specified. %val% represents the value of the control.
    • E.g.
    wrapped: 'weight=c(%val%),\n'

Destination Variable List Control Sample Code

  independent: {
    el: new dstVariableList(config,{
      label: localization.en.independent,
      no: "independent",
      required: true,
      filter:"String|Numeric|Logical|Ordinal|Nominal|Scale",
      extraction: "NoPrefix|UsePlus",
    })
  },


Sample RCode For Substitution of Destination Variable Selection

  • Reference the value of the no property of the control enclosed in the format required by the Squirrelly templating engine within the R code, see the example below the no property is independent. Note, in the example below the glm function takes a number of parameters, i.e. the modelname, the dependent variable and the independent variables. In this example we are concerned with the independent variable
    • E.g.
    {{selected.independent | safe}}
    Rcode:`{{selected.modelname | safe}}= glm({{selected.dependent | safe}} ~ {{selected.independent | safe}}….`

Sample Dialogs for Destination Variable List Control

  • Under top level navigation “Model Fitting > Regression > Linear, Basic”

Destination Dataset List Control

  • Drag and Drop/Move/ Copy one or more Datasets from the Source Dataset List to the Destination Dataset List Control

  • Optionally force the user to select a Dataset (Dialog will not execute unless the user adds a Dataset)


Destination Dataset List Control Properties

  • no: unique id (each control within a dialog must have a unique id). This unique id is used in the R code to substitute the control content
    • E.g.
    no: "in1"
  • label: String displayed above the Dataset control
    • E.g.
    label: "Select the 1st Dataset"
  • required: Optionally force the user to specify a value in the Dataset control. Dialog will not execute unless a user specifies a value. Default is false.
    • E.g.
    required:false
  • filter: Control the types of entries this control can contain
    • E.g.
    filter: "Dataset" allows only datasets
  • extraction: Control how the Dataset entered gets substituted in the R code
    • E.g. Following substitutes datasets data1, data2.. entered as data1, data2
    extraction: "NoPrefix|UseComma"
    • E.g. Following substitutes datasets data1, data2.. entered as “data1”, “data2”
    extraction: "NoPrefix|UseComma|Enclosed"

Destination Dataset List Control Sample Code

  in1: {
    el: new dstVariableList(config,{
      label: localization.en.in1,
      no: "in1",
      filter: "Dataset",
      extraction: "UseComma|Enclosed",
      required: true.
    })
  },


Sample RCode For Substitution of Destination Dataset List Control Selection

  • Reference the value of the no property of the control enclosed in the format required by the Squirrelly templating engine within the R code, see the example below the value of the no property is in1.
    • E.g.
    {{selected.in1 | safe}}
    Rcode:`paste( "{{selected.mergetype | safe}}","(",{{selected.in1 | safe}},",",{{selected.in2 | safe}},",","by = c(",by.text,"),","{{selected.suffix | safe}}",")")`

Sample Dialogs for Destination Dataset List Control

  • See top level navigation Datasets>Merge>Merge

TextBox Control

  • Allows a user to enter a string
  • Optionally enforce entering a number or a character string
  • Optionally enforce entering a string that conforms to R’s rules for naming objects
  • Optionally specify a left, top and/or bottom margin
  • If a user enters the name of a dataset in the textbox, you can optionally prompt the user to overwrite the dataset if it exists
  • Optionally specify a width


TextBox Control Properties

  • no: unique id (each control within a dialog must have a unique id) This unique id is used in the R code to substitute the control content

    • E.g.
    no: 'modelname'
  • label: String displayed above the textbox

    • E.g.
    label: "Enter model name"
  • placeholder: Optional default string displayed in the textbox, default is the empty string.

    • E.g.
    placeholder: "Logistic1"
  • required: Optionally force the user to enter a value in the textbox. Dialog will not execute unless a user specifies a value. Default is false.

    • E.g.
    required:false
  • allow_spaces: Optionally enforce entering a string that conforms to R’s rules for naming objects, default is false i.e., enforce R rules

    • allow_spaces:false
    • NOTE: if you want to force a user to enter only numerics, you need to set properties as below
    • E.g.
    allow_spaces:true
    Type: "numeric"
    • NOTE: if you want to force a user to enter strings with spaces, you need to set properties as below
    allow_spaces:true
    Type: "character"
  • extraction: Control how the entered text gets substituted in the R code

    • E.g. Following substitutes text as is
    extraction: "TextAsIs" 
    • E.g. Following creates an R array from comma separated input i.e. var1,var2 is converted to c(‘var1’, ‘var2’)
    extraction: "CreateArray" 
    • E.g. Following prefixes the text entered by the datasetname
    extraction: "Prefix" 
    • E.g. Following encloses the text entered by () and prefixes the text entered by the datasetname
    extraction: "Prefix|Enclosed" 
    • E.g. Following removes spaces from the string and then creates an array as above
    extraction: "CreateArray|RemoveSpaces“ 
  • type: Optionally force the user to enter a numeric or character, defaults to character

    • E.g. Following allows the user to enter a character string
    type: "character"
    • E.g. Following forces the user to enter a number
    type: "numeric"
  • value: Optionally display a value in the TextBox when its displayed

    • E.g.
    value: "Logistic1"
  • overwrite: If a user enters the name of a dataset or variable name in the textbox, you can optionally prompt the user to overwrite the dataset or variable (in the active dataset) if it exists

    • E.g.
    overwrite: "dataset",
    • E.g.
    overwrite: "variable",
  • style: Optionally customize left, top and bottom margins to improve layout. We use a relative scale from 1-5

    • E.g. Following lets left margin to 1, top margin to 1 and bottom margin to 3
    style="ml-1 mt-1 mb-3"
    • E.g. Following sets only the left margin to 2
    style="ml-2"
    • E.g. Following sets only the bottom margin to 2
    style="mb-2"
  • ml: Optionally customize left margin to improve layout. We use a relative scale from 1-5

    • E.g.
    ml:2

    Note: ml only works when a textbox is below a checkbox, it does not work when the textbox is the 1st control

  • wrapped: Allows you to wrap the results of the control within another string. For example, just say you want to pass the parameter weights = c(“variable name”) to a function but only when the weights value was specified. %val% represents the value of the control.

    • E.g.
    wrapped: 'weight=c(%val%),\n'
  • width: Specify the RELATIVE width of the textbox.This allows you to control whether the textbox occupies 25%, 50%, 75% or 100% of the available width. These are the ONLY options supported, you cannot specify any arbitrary width. The following options are available “w-25”, “w-50”, “w-75”, “w-100” with “w-75” being the default.

    • E.g.
    width: "w-25"


TextBox Control Sample Code

  • Sample Code for entering strings that must conform to R object name rules

    • NOTE: You don’t have to specify allow_spaces: “false” and type: “character” as these are the defaults
  newdatasetname: {
    el: new input(config, {
      no: 'newdatasetname',
      label: localization.en.newdatasetname,
      placeholder: "",
      extraction: "TextAsIs",
      type: "character",
      value: "",
      ml: 4,
      width:"w-25",
    })
  },


  • Sample Code for entering strings in the textbox/input control that must conform to R object name rules with the option to prompt to check if the object exists, the property overwrite: “dataset” checks if the dataset exists and prompts to overwrite
  newdatasetname: {
    el: new input(config, {
      no: 'newdatasetname',
      label: localization.en.newdatasetname,
      placeholder: "",
      extraction: "TextAsIs",
      type: "character",
      overwrite: "dataset",
      value: "",
      ml: 4,
      width:"w-100",
    })
  },


  • Sample Code for entering strings that contain spaces, note specifying type: “character” is not necessary as this is the default type for a TextBox Control
newdatasetname: {
      el:  new input(config, {
      no: 'specify_a_title',
      label: localization.en.specify_a_title,
      placeholder: "Chart title",
      allow_spaces: true,
      extraction: "TextAsIs"
    })
  },


  • Sample Code for entering strings that contain numerics, note that numerics are not valid R object names hence allow_spaces:true and type: “numeric”
newdatasetname: {
      el:  new input(config, {
      no: 'ci',
      allow_spaces: true,
      type: "numeric",
      label: localization.en.ci,
      placeholder: "0.995",
      extraction: "TextAsIs"
    })
  },


Sample RCode For Substitution of TextBox Contents

  • Reference the value of the no property of the control enclosed in the format required by the Squirrelly templating engine within the R code, see the example below the value of the no property is “modelname”
    • E.g.
    {{selected.modelname | safe}}
    • E.g.
    Rcode:`{{selected.modelname | safe}} = glm({{selected.dependent | safe}} ~…`


Sample Dialogs for TextBox Control

  • Under top level navigation Model Fitting > Regression > Linear, Basic

CheckBox Control

  • Allows a user to click a checkbox
  • Optionally enable 1 or more dependent controls
  • Optionally set margins to customize placement on the dialog
  • Optionally force the placement of the control on a new line


CheckBox Control Properties

  • no: unique id (each control within a dialog must have a unique id) This unique id is used in the R code to substitute the code associated with the checkbox selection
    • E.g.
    no: "generateplotchk"
  • label: String displayed to the right of the control
    • E.g.
    label:"Plot residuals vs fitted, normal Q-Q, scale-location…"
  • required: Optionally force the user to check the box. Dialog will not execute unless the user checks the box.
    • E.g.
    required:false
  • bs_type: The type of checkbox, we currently support “checkbox” which is the default and “valuebox”. When bs_type is set to “valuebox” the strings associated with the true_value and false_value are replaced. When bs_type is set to “checkbox” or the property bs_type is NOT specified the TRUE or FALSE is returned depending on whether the checkbox is checked or unchecked. Note: true_value and false_value are only valid for bs_type = “valuebox”
    • E.g. 1
    bs_type: “checkbox”
    bs_type: “valuebox”
  • state: Sets the state of the checkbox
    • E.g. Following ensures the checkbox is selected
    state: "checked"
    • E.g. Following ensures the checkbox is unselected
    state: ""
  • extraction: Control how the entered text gets substituted in the R code
    • E.g. Following substitutes text true when checkbox is selected, false otherwise
    extraction: "Boolean"
    • E.g. Following substitutes the string associated with the key true_value when checked and false_value when unchecked
    extraction: "TextAsIs"
  • true_value: Used when extraction is set to BooleanValue/TextAsIs. The string associated with true_value is substituted when the checkbox is checked
    • E.g.
    true_value: "This is true"
  • false_value: Used when extraction is set to BooleanValue/TextAsIs.. The string associated with false_value is substituted when the checkbox is unchecked
    • E.g.
    false_value: "This is false"
  • dependant_objects: Lists the unique id (value associated with the no property) that get enabled when the checkbox is selected. You can also force a user to enter a value in a dependent textbox when the checkbox is selected. See Example 5 below. SEE SAMPLE7.JS FOR EXAMPLES.

NOTE THE INCORRECT SPELLING OF DEPENDANT IN DEPENDANT_OBJECTS BELOW. WE WILL CORRECT THIS IN A UPCOMING UPDATE

  • E.g.
  dependant_objects: ["input_no_value", "input_value"]
  • style: Optionally customize left, top and bottom margins to improve layout. We use a relative scale from 1-5
    • E.g. Following lets left margin to 1, top margin to 1 and bottom margin to 3
    style="ml-1 mt-1 mb-3"
    • E.g. Following sets only the left margin to 2
    style="ml-2"
    • E.g. Following sets only the bottom margin to 2
    style="mb-2"


Sample CheckBox Control Code

  • Example 1: Default checkbox that substitutes TRUE or FALSE in syntax depending on whether its checked or not
  Summary: {
    el: new checkbox(config, {
      label: localization.en.Summary,
      no: "chk5",
      extraction: "Boolean"
    })
  },


  • Example 2: Default checkbox that substitutes the strings associated with the true_value and false_value when checked/unchecked newline:true forces placement of the checkbox on a new line
  showResultsinOutput: {
    el: new checkbox(config, {
      label: localization.en.showResultsinOutput,
      no: "showResultsinOutput",
      bs_type: "valuebox",
      extraction: "TextAsIs",
      true_value: "TRUE",
      false_value: "FALSE",
    })
  },
  
  
  distinct: {
    el: new checkbox(config, {
      label: localization.en.distinct,
      no: "distinct",
      style: "mt-2",
      bs_type: "valuebox",
      extraction: "TextAsIs",
      true_value: "%>%\n\tdistinct",
      false_value: " ",
    })
  },


  • Example 3: newline:true forces the placement of the checkbox on a new line
  distinct: {
    el: new checkbox(config, {
      label: localization.en.distinct,
      no: "distinct",
      style: "mt-2",
      bs_type: "valuebox",
      extraction: "TextAsIs",
      true_value: "%>%\n\tdistinct",
      false_value: " ",
      newline: true,
    })
  },


  • Example 4: Enable the dependent control with no: “variablename” when the checkbox is checked

    NOTE THE INCORRECT SPELLING OF DEPENDANT IN DEPENDANT_OBJECTS BELOW. WE WILL CORRECT THIS IN A UPCOMING UPDATE

  storeClusterInDataset: {
    el: new checkbox(config, {
      label: localization.en.stroreClusterInDataset,
      no: "storeclusterInDataset",
      dependant_objects: ["variablename"],
      extraction: "Boolean"
    })
  },
  
    variablename: {
                el: new input(config, {
                    no: 'variablename',
                    label: localization.en.variablename,
                    ml: 4,
                    placeholder: "",
                    type: "character",
                    extraction: "TextAsIs",
                    value: ""
                })
            },


  • Example 5: Enable the dependent control with no: “variablename” when the checkbox is checked and force the user to enter a value (when the checkbox is checked). Setting required:true in the checkbox forces the user to enter a value. When a value is not entered, the user gets a message when the dialog is executed.

    NOTE THE INCORRECT SPELLING OF DEPENDANT IN DEPENDANT_OBJECTS BELOW. WE WILL CORRECT THIS IN A UPCOMING UPDATE

  storeClusterInDataset: {
    el: new checkbox(config, {
      label: localization.en.stroreClusterInDataset,
      no: "storeclusterInDataset",
      required: true,
      dependant_objects: ["variablename"],
      extraction: "Boolean"
    })
  },
  
   variablename: {
                el: new input(config, {
                    no: 'variablename',
                    label: localization.en.variablename,
                    ml: 4,
                    placeholder: "",
                    type: "character",
                    extraction: "TextAsIs",
                    value: ""
                })
            },


Sample RCode For Substitution of CheckBox Contents

  • Reference the value of the no property of the control, see the example below the value of the no property is “chkbox1”
    • E.g.
    {{selected. chkbox1 | safe}}
    • E.g.
    Rcode:`correct={{selected.chkbox1 | safe}}`


Sample Dialogs For CheckBox Control

  • See “Analysis > Means > ANOVA, 1 and 2 way” for extraction: “TextAsIs”
  • See Analysis>Cluster>Kmeans cluster for use of extraction: “Boolean”
  • See Analysis>Cluster>Kmeans cluster for use of dependant_objects property
  • See Analysis>Cluster>Hierarchical cluster for an example where you are forced to enter a value in a dependent textbox when the checkbox associated with storing cluster names in the dataset is checked
  • SEE SAMPLE7.JS FOR EXAMPLES OF DEPENDENT OBJECTS

RadioButton Control

  • Allows a user to select a Radiobutton amongst a group of RadioButtons
  • Optionally enable 1 or more dependent controls
  • Optionally set margins to customize placement on the dialog


RadioButton Control Properties

  • no: unique id for the group of radio buttons (each group of radiobuttons within a dialog must have a unique id). This unique id is used in the R code to substitute the code associated with the checkbox selection

    • E.g.
    no: "grp1"
  • label: String displayed to the right of the radio button control

    • E.g.
    label: "Median"
  • increment: Unique id of the radio button within the group of radio buttons.

    • E.g.
    increment: "Median"
  • state: Sets the state of the radio button

    • E.g. Following ensures the radio button is selected
    state: "checked"
    • E.g. Following ensures the radio button is unselected
    state: ""
  • extraction: Control how R code gets generated when the radio button is selected

    • E.g. Following substitutes value of the value property
    extraction: “ValueAsIs"
  • value: Holds the string that gets substituted when the value is selected

    • E.g.
    value: "stats::median"
  • dependant_objects: Optionally lists the unique id (value associated with the no property) of the control(s) that get enabled when the radio button is selected

    • NOTE: WHEN A RADIOBUTTON IS A DEPENDENT OBJECT E.G. YOU HAVE A CHECKBOX AND YOU WANT THE RADIOBUTTON TO BE ENABLED WHEN THE CHECKBOX IS CHECKED, THE ID OF THE RADIOBUTTON IN THE DEPENDANT_OBJECTS NEEDS TO BE CONSTRUCTED BY CONCATENATING THE no PROPERTY AND THE INCREMENT PROPERTY SEPARATED BY _ SEARCH FOR checkbox_for_radiogroup IN SAMPLE7.JS FOR AN EXAMPLE

    • NOTE THE INCORRECT SPELLING OF DEPENDANT IN DEPENDANT_OBJECTS BELOW. WE WILL CORRECT THIS IN A UPCOMING UPDATE

    • E.g.

  dependant_objects: ["input_no_value", "input_value"]
  • syntax: Used to override the default substitution when the radio button is selected and substitute the name of the active dataset
    • E.g.
    syntax: "{{dataset.name}}“
  • style: Optionally customize left, top and bottom margins to improve layout. We use a relative scale from 1-5
    • E.g. Following lets left margin to 1, top margin to 1 and bottom margin to 3
    style="ml-1 mt-1 mb-3"
    • E.g. Following sets only the left margin to 2
    style="ml-2"
    • E.g. Following sets only the bottom margin to 2
    style="mb-2"


Sample RadioButton Control Code

  • Example 1: 2 radio buttons within the same group with 1 checked
  median: {
    el: new radioButton(config, {
      label: localization.en.median,
      no: "gpbox1",
      increment: "median",
      value: "stats::median",
      state: "checked",
      extraction: "ValueAsIs"
    })
  },
  
  mean: {
    el: new radioButton(config, {
      label: localization.en.mean,
      no: "gpbox1",
      increment: "mean",
      value: "base::mean",
      state: "",
      extraction: "ValueAsIs"
    })
  },


  • Example 2: Radio button with a dependent control, the dependent control with no: “newdatasetname” is enabled when the radio button is checked and disabled when unchecked

    • NOTE THE SPELLING OF DEPENDANT IN DEPENDANT_OBJECTS IS INCORRECT. WE WILL ADDRESS THIS IN A FUTURE UPDATE.
  New: {
    el: new radioButton(config, {
      label: localization.en.New,
      no: "rd",
      increment: "New",
      value: "",
      state: "checked",
      extraction: "ValueAsIs",
      dependant_objects: ['newdatasetname']
    })
  },


  • Example 3: Radio button with a dependent control, the dependent control with no: “newdatasetname” is NOT only enabled when the radio button is checked and disabled when unchecked but you can ALSO force a user to enter a value in a textbox when the radio button is selected. To do so, you need to set the required:true property on the radiobutton and it will force you to enter a value in the associated dependent objects associated with that radio button. In the example below, if prefix or suffix is selected, the user is forced to enter a prefix or suffix.

    • NOTE THE SPELLING OF DEPENDANT IN DEPENDANT_OBJECTS IS INCORRECT. WE WILL ADDRESS THIS IN A FUTURE UPDATE.
            suffix: { 
                el: new radioButton(config, { 
                    label: localization.en.suffix, 
                    no: "grp10", 
                    increment: "suffix", 
                    value: "Suffix", 
                    state: "checked", 
                    required:true,
                    extraction: "ValueAsIs",
                    dependant_objects: ["enterSuffix"] }) },
            
            enterSuffix: {
                el: new input(config, {
                    no: 'enterSuffix',
                    label: localization.en.enterSuffix,
                    placeholder: "",
                    extraction: "TextAsIs",
                    value: "",
                    ml: 4,
                    allow_spaces:true,
                }),
              },
            prefix: { 
            el: new radioButton(config, { 
                    label: localization.en.prefix, 
                    no: "grp10", 
                    increment: "prefix", 
                    value: "Prefix", 
                    state: "", 
                    required:true,
                    extraction: "ValueAsIs", 
                    dependant_objects: ["enterPrefix"] }) },
            
            enterPrefix: {
                el: new input(config, {
                    no: 'enterPrefix',
                    label: localization.en.enterPrefix,
                    placeholder: "",
                    extraction: "TextAsIs",
                    value: "",
                    ml: 4,
                    type: "character"
                }),
            },
            overwrite: { 
            el: new radioButton(config, { 
                    label: localization.en.overwrite, 
                    no: "grp10", 
                    increment: "overwrite", 
                    value: "Overwrite", 
                    state: "", 
                    extraction: "ValueAsIs", 
                    }) },
  


  • Example 4: When the syntax property is set to “{{dataset.name}}” the radiobutton control is substituted with current dataset in the R code
  Existing: {
    el: new radioButton(config, {
      label: localization.en.Existing,
      no: "rd",
      increment: "Existing",
      value: "X",
      state: "",
      syntax: "{{dataset.name}}",
      extraction: "ValueAsIs",
    })
  },


Sample RCode For Substitution of RadioButton Group Selection

  • Reference the value of the no property of the control, see the example below the value of the no property is “gpbox1”
    • E.g.
    {{selected.gpbox1 | safe}}
    • E.g.
    Rcode:`leveneTest( {{selected.tvarbox1 | safe}} ~ interaction({{selected.tvarbox3 | safe}}), data={{dataset.name}}, center={{selected.gpbox1 | safe}} )`


Sample Dialogs For RadioButton Control

  • See Analysis>Variance>Levene’s Test
  • See Datasets>Subset for how the dependant_objects property is used
  • See Datasets>Subset for how the syntax is used
  • See Variables>Transform for now you are forced to enter a value in the dependent textbox when the radiobutton is selected
  • SEE SAMPLE7.JS FOR EXAMPLES OF DEPENDENT OBJECTS

Label Control

  • Enter text
    • Serve as a heading to group options
    • Contextual test to guide a user
  • Optionally set the size of the text
  • Optionally set margins to customize placement on the dialog


Label Control Properties

  • label: The string displayed
    • E.g.
    label: "Function to compute the center of each group"
  • h: Control the size
    • E.g
    h: 5
    h: 3
  • style: Optionally customize left, top and bottom margins to improve layout. We use a relative scale from 1-5
    • E.g. Following lets left margin to 1, top margin to 1 and bottom margin to 3
    style="ml-1 mt-1 mb-3"
    • E.g. Following sets only the left margin to 2
    style="ml-2"
    • E.g. Following sets only the bottom margin to 2
    style="mb-2"


Label Control Sample Code

  • Example 1:
  label1: {
    el: new labelVar(config, {
      label: localization.en.label1, 
      style: "mt-3", 
      h:5
    })
  },


Sample RCode For Substitution of Label Control

  • The Label control is meant for displaying text on the dialog. Its contents are not substituted in R code, the print, cat and other functions in R meet this need


Sample Dialogs For Label Control

  • See Analysis>Variance>Levene’s Test

Pre-Formatted Text Control

  • Enter pre-formatted text to control the placement of new line characters
  • Optionally set the size of the text


Pre-Formatted Text Control Properties

  • label: String displayed
    • E.g.
    label: "Subsetting criteria is applied against each row, see examples below. \n1: Select rows"
  • h: Control the size
    • E.g.
    h:5
    h:3


Pre-Formatted Text Control Sample Code

  • Example 1:
  label12: {
    el: new preVar(config, {
      no: "label12",
      label: localization.en.label12, 
      h:6
    })
  },


Sample RCode For Substitution of the Pre-Formatted Text Control

  • The Label control is meant for displaying text on the dialog. Its contents are not substituted in R code, the print, cat and other functions in R meet this need


Sample Dialogs For Pre-Formatted Text Control

  • See Datasets>Subset

ComboBox Control

  • Select one or more predefined items from a list
  • Optionally force a single or multi-item selection
  • Optionally pre-select one or more items
  • Allows a user to enter a string


ComboBox Control Properties

  • no: unique id (each control within a dialog must have a unique id) This unique id is used in the R code to substitute the control selections
    • E.g.
    no: 'testStatistic'
  • label: String displayed above the ComboBox
    • E.g.
    label: "Test statistic"
  • multiple: Enable single or multiple selections.
    • E.g. Following is for single selection
    multiple: false
    • E.g. Following is for multiple selections
    multiple: true
  • required: Optionally force the user to make a selection. Dialog will not execute unless a user makes a selection. Default is false.
    • E.g.
    required:false
  • extraction: Control how the entered text gets substituted in the R code
    • E.g. Following encloses the selections in double quotes and separates each selection by a comma
    extraction: "NoPrefix|UseComma"
  • options: The predefined values displayed in the ComboBox
    • E.g.
    options: ["Hotelling-Lawley", "Pillai", "Roy", "Wilks"]
  • default: The default item(s) selected
    • E.g.
    default: "Wilks"


ComboBox Control Sample Code

  • Sample Code for a ComboBox Control
  testStatistic: {
    el: new comboBox(config, {
      no: "testStatistic",
      label: localization.en.testStatistic,
      multiple: false,
      extraction: "NoPrefix|UseComma",
      options: ["Hotelling-Lawley", "Pillai", "Roy", "Wilks"],
      default: "Wilks"
    })
  },


Sample RCode For Substitution of ComboBox Contents

  • Reference the value of the no property of the control, see the example below the value of the no property is “testStatistic”

    • E.g.
    {{selected.testStatistic | safe}}
    • E.g.
    Rcode:`BSkyMANOVASummary <- summary({{selected.modelname | safe}}, test = c("{{selected.testStatistic | safe}}"))`


Sample Dialogs For ComboBox Control

  • See Analysis>Means>MANOVA

Parent-Child ComboBox Control

  • Select one predefined items from a parent list and the child list gets populated by pre-defined items


Parent-Child ComboBox Control Properties

  • no: unique id (each control within a dialog must have a unique id) This unique id is used in the R code to substitute the parent control selection
    • E.g.
    no: 'family'
  • nochild: unique id of the child control. Every child must have a unique id within a dialog. This unique id is used in the R code to substitute the child control selection
    • E.g.
    nochild: 'combokid'
  • label: String displayed above the Parent Combobox
    • E.g.
    label: “Select a family and link function"
  • multiple: Enable single or multiple selections within the child ComboBox.
    • E.g. Following is for single selection
    multiple: false
    • E.g. Following is for multiple selections
    multiple: true
  • extraction: Control how the selected entry gets substituted in the R code
    • E.g. Following encloses the selection(s) in double quotes and separates each selection by a comma
    extraction: "NoPrefix|UseComma"
  • options: The predefined values displayed in the parent combobox and the associated values displayed in the child combobox when the value in the parent is selected
    • E.g.
    options: [ { "name": "gaussian", "value": ["identity", "inverse", "log"] }]


Parent-Child ComboBox Control Sample Code

  • Sample Code for a Parent Child ComboBox Control
  family: {
    el: new comboBoxWithChilderen(config, {
      no: 'family',
      nochild: 'combokid',
      label: localization.en.family,
      multiple: false,
      extraction "NoPrefix|UseComma",
      options: [
          { "name": "gaussian", "value": ["identity", "inverse", "log"] },
          { "name": "binomial", "value": ["logit", "probit", "cauchit","log","cloglog"] },
          { "name": "poisson", "value": [ "log","identity", "sqrt"] },
          { "name": "Gamma", "value": ["inverse","identity",  "log"] },
          { "name": "inverse.gaussian", "value": ["1/mu^2","identity", "inverse", "log" ] },
          { "name": "quasi", "value": [ "logit","probit","cloglog","identity","inverse", "log", "1/mu^2","sqrt"     ] },
          { "name": "quasibinomial", "value": ["logit", "probit", "cloglog"] },
          { "name": "quasipoisson", "value": ["log","identity",  "sqrt"] },
      ]
    })
  },


Sample RCode For Substitution of Parent-Child ComboBox Contents

  • Reference the value of the no property of the control, see the example below the value of the no property is “family” and value of the nochild property is “combokid”

    • E.g.
    {{selected.family| safe}}
    • E.g.
    {{selected.combokid| safe}}
    • E.g.
    Rcode:`…family ={{selected.family | safe}}(link="{{selected.combokid | safe}}…`


Sample Dialogs For Parent-ChildComboBox Control

  • See Model Fitting>GLZM

inputSpinner Control

  • Select a numeric value by mousing over the control and clicking the up or bottom arrows to select a value
  • Set an initial value
  • Set an increment
  • Set a min value
  • Set a max value


inputSpinner Control Properties

  • no: unique id (each control within a dialog must have a unique id) This unique id is used in the R code to substitute the control value

    • E.g.
    no: "box1"
  • label: String displayed above the inputSpinner control

    • E.g.
    label: "Confidence Interval"
  • min: The minimum value

    • E.g.
    min:0
  • max: The maximum value

    • E.g.
    max:1
  • step: The amount the value displayed increments/decrements when the up arrow/down arrow is clicked

  • value: The initial value displayed when the control is rendered

    • E.g.
    value:0.95
  • extraction: Control how the entered value gets substituted in the R code

    • E.g. Following substitutes the value as is
    extraction: "NoPrefix|UseComma"


inputSpinner Control Sample Code

  • Sample Code for an inputSpinner Control
  box1: {
    el: new inputSpinner(config, {
      no: 'box1',
      label: localization.en.txtbox1,
      min: 0,
      max: 1,
      step: 0.01,
      value: 0.95,
      extraction: "NoPrefix|UseComma"
    })
  },


Sample RCode For Substitution of inputSpinner Contents

  • Reference the value of the no property of the control, see the example below the value of the no property is “box1”
    • E.g.
    {{selected.box1 | safe}}
    • E.g.
    Rcode:`…conf.level={{selected.box1 | safe}}`


Sample Dialogs For inputSpinner Control

  • See Analysis>Proportions>Binomial Test

Advanced Slider Control

  • Select a numeric value by moving the dot on the scale or typing in a value
  • Set an initial value
  • Set an increment
  • Set a min value
  • Set a max value


Advanced Slider Control Properties

  • no: unique id (each control within a dialog must have a unique id) This unique id is used in the R code to substitute the control value

    • E.g.
    no: "cilevel"
  • label: String displayed above the Advanced Slider control

    • E.g.
     label: "Confidence Interval"
  • min: The minimum value

    • E.g.
    min:0
  • max: The maximum value

    • E.g.
    max:1
  • step: The amount the value displayed increments/decrements when the top/bttom arrows are clicked with the slider ball is clicked

  • value: The initial value displayed when the control is rendered

    • E.g.
    value:0.95
  • extraction: Control how the entered value gets substituted in the R code

    • E.g. Following substitutes the value as is
    extraction: "NoPrefix|UseComma"


Advanced Slider Control Sample Code

  • Sample Code for an Advanced Slider Control
  cilevel: {
    el: new advancedSlider(config,{
      no: 'cilevel',
      label: localization.en.cilevel,
      min: 0,
      max: 1,
      step: 0.05,
      value: 0.95,
      extraction: "NoPrefix|UseComma"
    })
  },


Sample RCode For Substitution of Advanced Slider Contents

  • Reference the value of the no property of the control, see the example below the value of the no property is “cilevel”
    • E.g.
    {{selected.cilevel | safe}}
    • E.g.
    `Rcode:`…conf.level={{selected.cilevel | safe}}`


Sample Dialogs For Advanced Slider Control

  • See Agreement>Method>Cohen’s Kappa

Compute Builder Control

* Simplifies the creation of an expression/formula by providing a set of arithmetic, logical, mathematical, string, type conversion, statistical, random number and date functions grouped into tabs * Click on the tab to see the functions corresponding to the name of the tab i.e. arithmetic, logical, mathematical… * Double clicking on a symbol will insert the symbol * You can drag and drop variables to create an expression/formula * Clicking a selected button will toggle its state. * To insert at a particular position in the textbox associated with the compute builder control, place the cursor in that position and drag and drop/move variable(s). * Mouse over a button for help.


  • no: unique id (each control within a dialog must have a unique id). This unique id is used in the R code to substitute the control content
    • E.g.
    no: "computeCtrl"
  • label: String displayed at the top of the compute builder control
    • E.g.
    label:"Expression builder"
  • required: Optionally force the user to specify an expression/formula. The dialog will not execute unless a user specifies a value. Default is false.
    • E.g.
    required:false
  • placeholder: Optionally display a string in the textbox associated with the compute builder control, default is an empty string.
    • E.g.
    placeholder: "Create your expression here, for e.g. var1+var2+ceiling(var3)"


#### Compute Builder Sample Code

  computeBuilder: {
                el: new computeBuilder(config, {
                    no: "computeCtrl",
                    required:true,
                    label: "Expression builder",
                    placeHolder: "For e.g. var1+var2+ceiling(var3)"
                })
            },


Sample RCode For Substitution of a compute builder control

  • Reference the value of the no property of the control, see the example below the value of the no property is “computeCtrl”
    • E.g.
    {{selected.computeCtrl | safe}}
    • E.g.
    Rcode:`{{selected.computeCtrl | safe}},`


Sample Dialogs For Compute Builder Control

  • See Variables>Compute>Compute

Formula Builder Control

  • Simplifies the creation of a formula by providing a set of operators
  • Clicking on the All N Way dropdown button gives you the ability to choose 2,3,4..10 way interactions. You do this by selecting the number (2,3,4…) of interaction terms desired and then selecting the variables from the source variable list and dragging and dropping these variables to the textbox associated with the Formula Builder Control. This will create all N way terms in the textbox associated with the formula builder control.
  • To create polynomial terms, select the number of terms and click on the polynomial terms button to select it, it will turn yellow, then drag and drop the variable from the source variable list (for which polynomial terms are desired) to the textbox associated with the formula builder control.
  • Double clicking on a symbol will insert the symbol
  • You can drag and drop variables to create a formula
  • Clicking a button will select it
  • Clicking a selected button will toggle its state.
  • To insert at a position, place the cursor at that position and drag & drop/move variable(s).
  • Mouse over a button for help.

Formula Builder Control Properties

  • no: unique id (each control within a dialog must have a unique id). This unique id is used in the R code to substitute the control content
    • E.g.
    no: "formulaCtrl"
  • label: String displayed above the variable control
    • E.g.
    label:“Formula Builder"
  • required: Optionally force the user to enter a value in this control. The dialog will not execute unless a user specifies a value. Default is false.
    • E.g.
    required:false
  • placeholder: Optionally display a string in the textbox associated with the formula builder control, default is the empty string.
    • E.g.
    placeholder: "Formula appears here"


#### Formula Builder Sample Code

  formulaCtrl: {
                el: new formulaBuilder(config, {
                    no: "formulaCtrl",
                    label: "Formula builder",
                    required:true,
                    placeHolder: "Create your formula here"
                })
            },
  


Sample RCode For Substitution of Formula Builder contents

  • Reference the value of the no property of the control, see the example below the value of the no property is “formulaCtrl”
    • E.g.
    {{selected.formulaCtrl | safe}}
    • E.g.
    Rcode:`~{{selected.formulaCtrl | safe}},`


Sample Dialogs For Formula Builder Control

  • See Model Fitting>Regression>Linear Regression, Advanced

Collapsible Panel

  • Collapsible panel that contains one or more controls
  • Click panel name to expand/collapse
  • Collapsible panel can contain the following controls
    • TextBox
    • Label
    • Preformatted Text
    • ComboBox including parent child ComboBox
    • Input Spinner
    • Advanced slider
    • Radio button
    • Checkbox


Collapsible Panel Control Properties

  • no: unique id (each control within a dialog must have a unique id)
    • E.g.
    no: "timeZoneOptions"
  • name: Name of the panel
    • E.g.
    name: "Advanced"


Collapsible Panel Sample Code

  • Sample Code for the Collapsible Panel Control
  var timeZoneOptions = {
    el: new optionsVar(config, {
      no: "timeZoneOptions",
      name: "Advanced",
      content: [
        objects.TimeZone.el,
      ]
    })
  },

TimeZone is a ComboBox Control within objects


Sample RCode For Substitution of Collapsible Panel

  • The collapsible panel groups controls within a panel and does not by itself substitute R code
  • The controls within a collapsible control contain variables/text… that can be dynamically substituted as per the documentation of the control


Sample Dialogs For Collapsible Panel Control

  • See Variables>Date To Character

File Open control

  • Open the file browser to select a file


File Open Control Properties

  • no: unique id for the file open control. This unique id is used in the R code to substitute the path (including the file name) to the file associated with the file open control selection
    • E.g.
    no: "importResp"
  • label: String displayed on the top of the file open control
    • E.g.
    label: "Select a file to open"
  • required: Optionally force the user to select a file to open. Takes values true or false
    • E.g.
    required:true
  • extraction: Control how R code gets generated when a file is selected with the file open control
    • E.g. Following extraction substitutes the full path (including file name) to the file selected
    extraction: "TextAsIs"

Sample File open control code

  • Example 1: Select a file to open
    importResp: {
                el: new fileOpenControl(config, 
                    {
                        no: "importResp", 
                        label: "Select a file to open",
                        extraction: "TextAsIs"
                    })
                },
            


Sample R Code For Substitution of the contents of the file open control

  • Reference the value of the no property of the control, see the example below the value of the no property is “importResp”
    • E.g.
    {{selected.importResp | safe}}
    • E.g.
    Rcode:`base::open({{selected.modelSelection | safe}}, file = "{{selected.importResp | safe}}")`


Sample Dialogs For file open control

  • See Model Fitting>Load Models

File Save control

  • Specify a new or existing file to save results to


File Save Control Properties

  • no: unique id for the file save control. This unique id is used in the R code to substitute the path to the file including the file name associated with the file save control selection
    • E.g.
    no: "importResp"
  • label: String displayed on the top of the file save control
    • E.g.
    label: "Select a new/existing file to save a model to"
  • required: Optionally force the user to select a new/existing file to save to. Takes values true or false
    • E.g.
    required:true
  • extraction: Control how R code gets generated when a file is selected with the file save control
    • E.g. Following substitutes the full path to the file selected
    extraction: "TextAsIs"

Sample File save control code

  • Example 1: Select a new/existing file to save results to
      importResp: {
                el: new fileSaveControl(config, 
                    {
                        no: "importResp", 
                        label: "Select a file to save a model to",
                        extraction: "TextAsIs",
                        required: "true"
                    })},


Sample R Code For Substitution of the contents of the file save control

  • Reference the value of the no property of the control, see the example below the value of the no property is “importResp”
    • E.g.
    {{selected.importResp | safe}}
    • E.g.
    Rcode:`base::save({{selected.modelSelection | safe}}, file = "{{selected.importResp | safe}}")`


Sample Dialogs For file save control

  • See Model Fitting>Save Models

Using default application theme when generating graphs with ggplot

When your dialogs create graphs, you would want them to use the default themes available in the BlueSky Statistics application so that titles, fonts, graph themes look consistent across the application. You can access the themes used in the graphs that ship with BlueSky Statistics by going to triple dot>Theme. A user can change these themes.

In order to do so, all you need to do is append a + {{selected.BSkyThemes | safe}} \n at the end of your ggplot function and we will automatically append a string that contains the default themes

  • E.g.
  ggplot(data={{dataset.name}}, aes(x = col[[1]])) +
                    geom_histogram(bins = {{selected.histBins | safe}}, 
                    alpha=1,  fill ="#727272", 
                    aes(y =..density..)) +
                    stat_function(fun = dnorm, 
                    args = list(mean = mean(var_list[[i]], na.rm = TRUE) , 
                      sd = sd(var_list[[i]], na.rm = TRUE)) , 
                      col = "#eaf820", size = 2) +
                    labs(x=names(col), title= paste("Histogram for variable", names(col))) +
                    xlab(names(col)) + 
                    ylab("Density") + {{selected.BSkyThemes | safe}} \n

Results in the following code being substituted

 geom_histogram(bins = 9, alpha=1,  fill ="#727272"  , aes(y =..density..)) +
                    stat_function(fun = dnorm, 
                        args = list(mean = mean(var_list[[i]], na.rm = TRUE) , 
                        sd = sd(var_list[[i]], na.rm = TRUE)) , 
                    col = "#eaf820", size = 2) +
                    labs(x=names(col), title= paste("Histogram for variable", names(col))) +
                    xlab(names(col)) + 
                    ylab("Density") + 
            theme_classic() + 
            theme(text=element_text(family="sans",
            face="plain",
          color="#000000",  size=12,
            hjust=0.5, vjust=0.5),
            plot.title=element_text(hjust=.5, size=18)) 

Exercises

All sample dialogs are located in the development folder in the installation directory (Default installation directory is c:\program files\BlueSky Statistics\10 folder)

Exercise 1: Installing a sample dialog

Follow the steps below

  1. Under the top level hamburger menu ( 3 sandwiched lines) click on Marketplace

  2. If you haven’t done so, select a file folder to save installed dialogs to. We will refer to this folder as the folder containing the marketplace dialogs. This must be a folder on your computer that you have write permissions to. The dialogs you are installing get copied here.

  3. Now choose a top level menu tab where you want your dialog to be installed to. To follow with this exercise, lets select the top level menu tab “Datasets”. This will ensure that the sample dialog will appear in the Datasets tab.

  4. Click the button “Select a Dialog” to Upload a sample dialog by browsing to the development folder in the installation directory (Default installation directory is c:\program files\BlueSky Statistics\10 folder)

  5. Select the dialog file Sample 1.js

  6. Click on the Upload button, this will upload the dialog and make it available in the Datasets menu for installation

  7. On successful upload, the screen will refresh and automatically scroll to the place on the Datasets tab where the newly installed dialog is available for you to install.

  8. Click on the Install button associated with the Sample 1 dialog, this will install the dialog into the top level menu.

  9. Click on Datasets in the top navigation, you will see the new dialog Sample 1 on the far right.

  10. Open a sample dataset and execute the newly installed dialog, it will allow you to build a simple regression model.

Exercise 2: Changing dialog properties on a dialog

The dialog you just installed (Sample 1.js), got copied to the file folder containing the marketplace dialogs. (You can access this folder location by going to the top level hamburger menu ( 3 sandwiched lines) and clicking on Marketplace ). Go ahead browse to the folder and open the dialog in notepad++ or a suitable javascript editor.

Follow the steps below

  1. Change the title of the dialog from “Sample 1” to “Linear Regression” In the “en” object change the value of the “title” property from “Sample 1” to “Linear Regression”. You can find the “en” object by simply searching for en)

  2. Change the text displayed in the top level navigation from “Sample 1” to “Linear Regression” In the “en” object change the value of the “navigation” property from “Sample 1” to “Linear Regression”

  3. Change the title in the Help overlay from “Sample 1” to “Linear Regression” In the “help” object change value of the “title” property from “Sample 1” to “Linear Regression”

  4. Change the placement of the textbox with caption “Enter Model name” from the top of the right column to the bottom of the right column Within the “content” object change right: [objects.modelname.el.content, objects.dependent.el.content, objects.independent.el.content, objects.weights.el.content], to right: [objects.dependent.el.content, objects.independent.el.content, objects.weights.el.content, objects.modelname.el.content ],

  5. Change the label of the weights control Within the en object change the value of the “weights” property from “Specify a variable with weights” to “Optionally Specify a variable with weights”

  6. Save the changes made to Sample 1.js (to the same file folder you specified in the Marketplace dialog)

  7. Navigate back to the Marketplace (go to the top level hamburger menu ( 3 sandwiched lines) and click on Marketplace), click on the Datasets tab, look for the Sample 1 dialog you just installed (you may need to scroll to the bottom).

  8. Click on the “Reload Dialog” button displayed to the right of the Sample 1 entry. You will see your changes when you relaunch the dialog.

  9. If you see errors, try and correct the errors. If you are unable to correct the errors, look at dialog Sample 1a.js. This file has all the modifications above and you can compare your edits with the edits in Sample 1a.js or alternately copy the contents of the sample 1a.js into Sample 1.js and save the file. Then reload the file as in steps 7 and 8 above.

  10. Relaunch the dialog and note how the textbox that captures the name of the model has moved to the bottom of the right column from the top. Note the changes to the Title of the dialog displayed in the navigation, on the main dialog and the Help overlay (click on the ? icon on the top right of the dialog) as well.

Exercise 3: Adding a checkbox control to the sample 1

  1. In this exercise we will add a new checkbox input control to the dialog. This will allow you to give the user the option to plot the regression model.

  2. Open Sample 1.js (in notepad++ or any suitable javascript editor) from the file folder you specified for the Marketplace dialogs (You can access this folder location by going to the top level hamburger menu ( 3 sandwiched lines) and clicking on Marketplace )and un-comment the code below to add the checkbox control to the dialog

 /*  generateplotchk: {
                el: new checkbox(config, {
                    label: localization.en.generateplotchk,
                    no: "generateplotchk",
                    style: "mt-2 mb-3",
                    bs_type: "valuebox",
                    extraction: "TextAsIs",
                    true_value: "TRUE",
                    false_value: "FALSE",
                })
            },*/
  1. Add the checkbox to the right column between the destination variable list that captures the independent variables and the variable list that captures the weights. To do so you add the string “objects.generateplotchk.el.content” to the value associated with the “right” property of the content object. The right property should look as below, so that the checkbox displays below the destination variable list that captures the independent variables.
right: [objects.modelname.el.content, objects.dependent.el.content, objects.independent.el.content, objects.generateplotchk.el.content, objects.weights.el.content],
  1. Save Sample 1.js

  2. Navigate back to the Marketplace (go to the top level hamburger menu ( 3 sandwiched lines) and click on Marketplace), click on the Datasets tab, look for the sample dialog (now called Linear Regression dialog as you changed the title above) you just installed (you may need to scroll to the bottom)

  3. Click on the “Reload Dialog” button. You will see your changes when you launch the dialog.

  4. If you see errors, try and correct the errors. If you are unable to correct the errors, look at sample 1b.js. This file has all the modifications above and you can compare your edits with the edits in Sample 1b.js or alternately copy the contents of the Sample 1b.js into Sample 1.js and save the file. Then reload the file as in steps 4 and 5 above.

  5. Open the Sample 1 dialog (now called Linear Regression from the Datasets top level menu)and verify that you see the checkbox to draw the plots.

  6. Note that the plots don’t draw when you select this option. We will write the R code to do this in Exercise 7.

Exercise 4: Changing the extraction property on the destination variable list control

  1. Open Sample 1.js (in notepad++ or any suitable javascript editor) from the file folder containing the marketplace dialogs (You can access this folder location by going to the top level hamburger menu ( 3 sandwiched lines) and clicking on Marketplace).

  2. Change the value of the extraction property of the destination variable list control that contains the independent variables from UsePlus to UseComma. The changed code will look like below

 independent: {
              el: new dstVariableList(config, {
                  label: localization.en.independent,
                  no: "independent",
                  required: true,
                  filter: "String|Numeric|Logical|Ordinal|Nominal|Scale",
                  extraction: "NoPrefix|UseComma",
              }), r: ['{{ var | safe}}']
          },
  1. Save Sample 1.js

  2. Navigate back to the Marketplace, click on the Datasets tab, look for the sample dialog you installed in the steps above (NOTE: the name is Linear Regression due to the change you made above, you may need to scroll to the bottom to see it).

  3. Click on the “Reload Dialog” button.

  4. If you see errors when you click the “Reload Button” try and correct the errors. If you are unable to correct the errors, look at Sample 1c.js. This file has all the modifications above and you can compare your edits with the edits in Sample 1c.js or alternately copy the contents of the Sample 1c.js into Sample 1.js and save the file. Then reload the file as in steps 4 and 5 above.

  5. Open the Sample 1 (now called Linear Regression from the Datasets tab) dialog and move some independent variables

  6. Display the syntax

  7. Execute the dialog and note the error message due to the fact that the independent variables don’t conform to the format that R expects.

  8. Revert the change made above and save the Sample 1.js and Reload to get the dialog to the original state.

Exercise 5: Changing the extraction properties on the textBox control

  1. Open Sample 1.js from the file folder containing the marketplace dialogs.

  2. Change the value of the extraction property of the destination variable list control that contains the independent variables from UseComma to UsePlus. The changed code will look like below

 independent: {
              el: new dstVariableList(config, {
                  label: localization.en.independent,
                  no: "independent",
                  required: true,
                  filter: "String|Numeric|Logical|Ordinal|Nominal|Scale",
                  extraction: "NoPrefix|UsePlus",
              }), r: ['{{ var | safe}}']
          },
  1. Change the value of the extraction property of the textbox control that contains the name of the model from TextAsIs to CreateArray. The changed code will look like below
  modelname: {
              el: new input(config, {
                  no: 'modelname',
                  label: localization.en.modelname,
                  placeholder: "",
                  required: true,
                  type: "character",
                  extraction: "CreateArray",
                  value: "LinearRegModel1"
              })
          },
  1. Save Sample 1.js

  2. Navigate back to the Marketplace, click on the Datasets tab, look for the sample dialog you installed (now called linear regression as you changed the title above)

  3. Click on the “Reload Dialog” button.

  4. If you see errors when you click the “Reload Button” try and correct the errors. If you are unable to correct the errors, look at Sample 1d.js. This file has all the modifications above and you can compare your edits with the edits in Sample 1d.js or alternately copy the contents of the sample 1c.js into sample 1.js and save the file. Then reload the file as in steps 4 and 5 above.

  5. Open the Sample 1 (now called Linear Regression from the Datasets tab) dialog and move some independent variables

  6. Display the syntax, note the incorrect syntax

  7. Execute the dialog and note the error message

Exercise 6:

Revert the change made in Exercise 4 and Exercise 5 and Reload to get the dialog to the original state.

Exercise 7:

  • Review the dialog Sample 2.js (in the development folder) that allows you to Reorder variables in the dataset alphabetically by inspecting the code in Notepad++ or a Javascript editor.

  • Note: The R function BSkySortDataset mentioned below is already created in the BlueSky Package

  • IDEALLY When 1st Radio Button is selected, you would want the code below to run
    • Reorder variables alphabetically in order A-Z
    {{dataset.name}} <- {{dataset.name}} %>%  dplyr::select(sort(names(.)))
  • When 2nd Radio Button is selected, code below must be run
    • Reorder variables alphabetically in order Z-A
    {{dataset.name}} <- {{dataset.name}} %>% dplyr::select(rev(sort(names(.))))
  • HOWEVER the radiogroup control with 2 radiobuttons, discussed in the RadioButton control above, returns a single value, for e.g. TRUE or FALSE. You could write a R function that accepts a single parameter alphabeticalSort. When alphabeticalSort = TRUE the function would sort the dataset alphabetically, When alphabeticalSort = FALSE, the dataset is sorted in reverse alphabetic order.
  • In sample 2.js the radioGroup would return
    • TRUE when Radio Button A-Z was selected
    • FALSE when Radio Button Z-A was selected
  BSkySortDataset  <- function (alphabeticalSort = TRUE, data = datasetName)
  {
    if (alphabeticalSort)
    {
      data<- data %>%  dplyr::select(sort(names(.)))
    } else 
    {
      data <- data %>% dplyr::select(rev(sort(names(.))))
    }
  }
  • The Dialog Sample 2.js invokes the R function below
  require(dplyr)
  {{dataset.name}} <- BSkySortDataset(alphabeticalSort ={{selected.rdgrp}}, data ={{dataset.name}})
  BSkyLoadRefresh("{{dataset.name}}" )
  • This approach has the following problems
    • People expect to see R Code from popular R packages
    • For more advanced users, the code below creates an unnecessary copy of the dataset, as in R when we pass an object to a function, we create a copy
    • We can solve this by passing the dataset name and then using eval(parse…)) this increases complexity
  • People expect to see R Code from popular R packages
    • Users prefer to see and learn dplyr code, see example below.
    require(dplyr)
    #Reorder variables alphabetically in order A-Z
    admit <- admit %>%  dplyr::select(sort(names(.)))
    BSkyLoadRefresh("admit")
    • Instead of
    admit <- BSkySortDataset(alphabeticalSort =TRUE, data =admit)
    BSkyLoadRefresh("admit")
  • Inorder to make this happen, we need to introduce conditional logic, please see the section below, Introducing the Squirrelly Templating Engine For Javascript

Introducing the Squirrelly Templating Engine For Javascript

  • The Squirrelly templating engine allows you to introduce conditional logic that tests the value of a javascript object. The javascript object corresponds to the value of the no property of the control. We support this for the following types of objects Checkbox Radiobutton Textbox
  • See reference material on the Squirrelly templating engine below
  • The sample code is as below
{{if (options.selected.rdgrp=="TRUE")}}
R code to execute when true
{{#else}}
R code to execute when false
{{/if}}
  • The {{#else}} is optional
{{if (options.selected.rdgrp=="TRUE")}}
R code to execute when false
{{/if}}
  • See dialog Sample 3.js, see RCode that dialog generates below
require(dplyr)
{{if (options.selected.rdgrp=="TRUE")}}#Reorder variables alphabetically in order A-Z\n{{dataset.name}} <- {{dataset.name}} %>%  dplyr::select(sort(names(.)))\n{{#else}}#Reorder variables alphabetically in order Z-A\n{{dataset.name}} <- {{dataset.name}} %>% dplyr::select(rev(sort(names(.))))\n{{/if}}
BSkyLoadRefresh("{{dataset.name}}" )

Other Sample Dialogs With Conditionals

  • See Sample 4.js, note there is no else. The code below can be re-purposed to generate the plots in Exercise 3.
  {{if (options.selected.generateplotchk == "TRUE")}}
  #Displaying plots\nplot({{selected.modelname | safe}})
  {{/if}} 
  • See Sample 5.js for an example of how you can test the contents of a TextBox control and nest {{if ((… with another {{if (…

Exercise 8 – Populating a textbox or Combobox with the results of a R function

You may need to create dialogs that populate a preformatted text control or combobox with the results of a R function. For example see Model Evaluation > Plot a Model. When you launch this dialog we automatically show you all the models of class lm (linear models) and glm (generalized linear models).

NOTE: This capability is only available with a combobox and a preformatted text control.
If used with a combobox the R function must return a character or numeric vector, each element of the vector returned will be displayed as an entry in the combobox. If used with a textbox, the R function must return a character string. The character string will be displayed in the preformatted text control.

  1. Open and inspect Sample 6.js
  2. You will see the property pre_start_r. This property holds the name of the R function that will be invoked and the user interface control that will be populated with the results of the R function call in the format
  pre_start_r: JSON.stringify({
                Value of the **no** property: "Name of the R function",})
  1. In the sample dialog, look for
  pre_start_r: JSON.stringify({
                modelselector1: "BSkyGetAvailableModels(c(\"lm\", \"glm\"))",})
  1. Look for the onclick property, as below. This property needs to be set to ensure that the R function gets called before the dialog is launched.
onclick: `r_before_modal("${config.id}")`,
modal_id: config.id


  1. NOTE: ALL DIALOGS THAT HAVE CONTROLS THAT ARE POPULATED BY R FUNCTIONS MUST HAVE THE modal_id property set to config.id, see below
nav: {
                name: "Name that displays in the navigation",
                icon: "suitable icon",
                onclick: `r_before_modal("${config.id}")`,
                modal_id: config.id
            },

Exercise 9 – see the dialog Sample 7.js. It is a dictionary of all the controls

Use this dialog as a starting point to copy/paste template controls into the new dialog you are building.

Exercise 10 – More advanced use cases

Here are a couple or more advanced scenarios 1. You want a single control to create different R code e.g. one R function needs the variables in the format c(“var1”,“var2”, “var3”) and another R function associated with the same dialog wants the variables in the format var1 + var2 + var3 2. You may want to perform some validation based on the data entered e.g. check whether the user logged in has write permissions to the path selected etc.

The cases above are handled on post processing after the user clicks the execute function.

Follow the steps below

  1. Open the dialog Sample 8.js
  2. Browse towards the bottom of the dialog. You will see a function called prepareExecution(instance)
  3. This function will give you a handle to the dialog just before the code to substitute the input specified by the user in the R code takes place
  4. There are a couple of lines of code in this sample that are important
var code_vars = {
            dataset: {
                name: $(`#${instance.config.id}`).attr('dataset') ? $(`#${instance.config.id}`).attr('dataset') : getActiveDataset()
            },
            selected: instance.dialog.extractData()
        }
  1. The variable code_vars contains the active dataset name and the values of all the input variables as specified by the default extraction property on each input control.
  2. The function extractData() does the hard work of iterating all the input control objects on the dialog and saving the values in a property with the name equal to the “no” property within the selected object, which inturn is within the code_vars variable
  3. The function renderR(code_vars) substitutes the values from the input object into the RCode. See the RCode property.
 const cmd = instance.dialog.renderR(code_vars);
           
  1. The line res.push({ cmd: cmd, cgid: newCommandGroup() }) saves the final R code so that it can be executed.
  res.push({ cmd: cmd, cgid: newCommandGroup() })
  return res;
  1. You can handle the case of a single control generating different R code e.g. one R function needs the variables in the format c(“var1”,“var2”, “var3”) and another R function associated with the same dialog wants the variables in the format var1 + var2 + var3 by creating a new variable, see below. NOTE: The new variables you create e.g. stringInteractionPlots must be in the RCode so that they can be dynamically substituted.
 vars = code_vars.selected.commaSepDest.toString();
            if (code_vars.selected.Interaction == "FALSE") {
                code_vars.selected.dependentVars = vars.replace(",", "*");
            }
            else {
                code_vars.selected.dependentVars = vars.replace(",", "+");
            }
            //Creating a string for interaction plots
            code_vars.selected.stringInteractionPlots = vars.replace(",", "~");
           

Common errors

When you write javascript code to create dialogs, just like any programmer, there is a likelihood that you will see the following errors. We do our best to check for these errors on dialog installation. What follows are some of the common errors you will encounter.

Missing commas

  1. Open Sample 9.js in notepad++ or a suitable javascript editor. You will see that it has a missing comma on line 98.
  2. Upload and install dialog Sample 9.js.
  3. You will see the error below
  4. NOTE: THE LINE NUMBER THAT WE DISPLAY IS NOT THE EXACT LINE NUMBER OF THE ERROR BUT AN CLOSE APPROXIMATION OF THE LINE NUMBER THAT THE ERROR OCCURED.
  5. Typically the syntax highlighting and open closing bracket alignment features with common javascript editors will make it easy to identify such errors.

Missing closing bracket

  1. Open Sample 10.js in notepad++ or a suitable javascript editor. You will see that it has a missing closing bracket on line 103.
  2. Upload and install dialog Sample 10.js.
  3. You will see the error below
  4. NOTE: THE LINE NUMBER THAT WE DISPLAY IS NOT THE EXACT LINE NUMBER OF THE ERROR BUT AN CLOSE APPROXIMATION OF THE LINE NUMBER THAT THE ERROR OCCURED.
  5. Typically the syntax highlighting and open closing bracket alignment features with common javascript editors will make it easy to identify such errors.

RCode references an object that is not present in the dialog

  1. Open Sample 11.js in notepad++ or a suitable javascript editor. You will see that RCOde (shown below) references a object modelname1 that is not defined. NOTE: the object modelname has a “no” property set to “modelname”
 RCode: `   
require(equatiomatic)
require(textutils)
#Creating the model
{{selected.modelname1 | safe}} = lm({{selected.dependent | safe}}~{{selected.independent | safe}}, {{ if (options.selected.weights != "")}}weights ={{selected.weights | safe}},{{/if}} na.action=na.exclude, data={{dataset.name}})
  1. Upload and install dialog Sample 11.js.

  2. Paste the syntax, you will see the line below. As the application could not find a control with a no property set to “modelname1”, it substitutes undefined

#Creating the model
undefined = lm(engine~weight+accel+year+origin+cylinder,  na.action=na.exclude, data=caranalysisDelete)
  1. Replace modelname1 by modelname as below, reload the dialog. The code generated will be correct.
 RCode: `   
require(equatiomatic)
require(textutils)
#Creating the model
{{selected.modelname | safe}} = lm({{selected.dependent | safe}}~{{selected.independent | safe}}, {{ if (options.selected.weights != "")}}weights ={{selected.weights | safe}},{{/if}} na.action=na.exclude, data={{dataset.name}})

Important tips

Tip 1. When using the Squirrelly templating engine to substitute the contents of a control where the control to be substituted is at the end of a line, see {{selected.modelname | safe}} below, the newline character gets removed by the templating engine, resulting in incorrect syntax.

Rcode:`
convert_lm_type = {{selected.modelname | safe}}
class(convert_lm_type) = "lm"
BSkyFormat(convert_lm_type)`

See incorrect R code generated when the newline character gets removed by the templating engine

convert_lm_type = linearModelclass(convert_lm_type) = "lm"
BSkyFormat(convert_lm_type)`

This can be addressed in the following ways 1. Place a ; at the end of the line, see below

Rcode:`
convert_lm_type = {{selected.modelname | safe}};
class(convert_lm_type) = "lm"
BSkyFormat(convert_lm_type)`

or 2. Place a newline character at the end of the line

Rcode:`
convert_lm_type = {{selected.modelname | safe}}\n
class(convert_lm_type) = "lm"
BSkyFormat(convert_lm_type)`

Tip 2. When you want to overlay a smoothing line on an existing graph, typically you generate the graph and then run the command to generate the smoothing line. With BlueSky Statistics we generate a new graphic device for every graphic command. The net result is when the command to draw the smoothing line is executed, the graphic device is already closed. To achieve the same effect enclose the graphic commands in

The code below will not show the line

qqnorm(residuals(model1))
qqline(residuals(model1))

The code below will display the line correctly

{
  qqnorm(residuals(model1))
  qqline(residuals(model1))
}

Removing BlueSky Statistics Dialogs that you installed

  1. Delete the “BlueSky Statistics” folder from “Roaming” directory (This applies to Windows operating system). On the Windows operating system, you can access the roaming folder by opening the Windows Explorer and typing %appdata% in the control that displays the path. The path of the folder is typically c:\users\\Appdata\Roaming

  2. Delete the user dialog folder (or just delete the entire contents of the folder). You can access the path that you set to save manually installed dialogs by clicking the hamburger menu ( 3 sandwiched lines) on the top left of the main application Window, click on Marketplace. If you have other files that are not related to the BlueSky Statistics application in this folder, then delete the dialog.json and the javascript files related to the user dialogs that you installed/uploaded.

Thank You