[SOLVED] module bug

Everything related to the development of modules in jamovi

by iainjgallagher » Sun Sep 24, 2017 11:06 am

Hi

I've created a module to generate qqplots (https://github.com/iaingallagher/qqplots) - fee free to test, comment etc. And thanks for making this so (relatively) easy :-)

I have a bug though, illustrated in the linked image below. With no variable to examine I have an error message in the plot presentation area. Any help would be appreciated.

Thanks,

Iain

https://github.com/iaingallagher/qqplots/blob/master/module_bug.png
iainjgallagher
 
Posts: 7
Joined: Sun Sep 24, 2017 10:51 am

by Ravi » Sun Sep 24, 2017 2:01 pm

Hi Iain,

Awesome! Good to hear that it's (relatively) easy. You're getting this error message because you are running the analyses no matter whether you assigned a variable or not. An easy fix is to first do a basic check and only run the code if a variable is assigned:

Code: Select all
if ( ! is.null(self$options$var)) {
   
    qqvar <- self$data[,self$options$var] # data to examine
    qqdata <- qqnorm(qqvar, plot.it=FALSE) # x & y coords
    plotData <- data.frame(x=qqdata$x, y=qqdata$y) # assembl DF for plotting
   
    image <- self$results$plot #set up for plotting
    image$setState(plotData)
}


Cheers,
Ravi
User avatar
Ravi
 
Posts: 140
Joined: Sat Jan 28, 2017 11:18 am

by iainjgallagher » Mon Sep 25, 2017 8:56 pm

Great, thanks. Working properly now. I'll probably try and make a start on 'Group by' functionality soon. Expect more questions!

iain
iainjgallagher
 
Posts: 7
Joined: Sun Sep 24, 2017 10:51 am

by Ravi » Wed Oct 04, 2017 3:56 pm

Cool! Already a couple of suggestions/tips.

Instead of allowing the user to only one plot variable you can allow them to define multiple plot variables. This way it's easier to check normality for multiple variables. In order to do this you need to change a couple of things.

First, change the type of "Plot Variable" from "Variable" to "Variables" in qqplot.a.yaml. This changes the options UI so that you can drag multiple variables into the "Plot Variable" box.

Next, you need to change the qqplot.r.yaml file so that multiple plots will be displayed in the results. Instead of a results object of type "Image", you now first need a results object of type "Array". That would look something like this (check here for an example in jmv):
Code: Select all
    - name: plots
      title: Q-Q Normal Plots
      type: Array
      description: an array of Q-Q plots
      items: (vars)
      template:
          title: $key
          type: Image
          renderFun: .plot


Last, you need to loop over your array results object as is done over here. So something like this:
Code: Select all
images <- self$results$plots
for (key in images$itemKeys) {
    image <- images$get(key=key)
    image$setState(plotData)
}


If you have any questions, let me know.
User avatar
Ravi
 
Posts: 140
Joined: Sat Jan 28, 2017 11:18 am


Return to Module development