Tiki and PluginR

Tiki and PluginR

Jyhem coding RR plugin settings variables directly from within RR

posts: 68 France

Hello Xavi,

Linked to my former issue (4 days scratching the web without a solution until today), I had another idea...

We already hacked RR plugin in order to have it write variables from tiki site, like lang, or group name.

I would like RR to do the opposite :

To define special calls in R script that are picked up by RR plugin as configuration parameters. Like: output width, height, output type (png - pdf - svg) etc...

This would give us the possibility to have a R script passing parameters to RR depending of some variables that are calculated, just before plotting/sending a html table.

posts: 1817 Catalan Countries

Hi Joël:

You have the possibility to use those params already in place (width, height, etc). See:

Regarding svg and pdf generation, they are out of order for me with latest tiki versions (e.g. Tiki12), I still didn't have time to investigate why and fix it.
But for sure there are many other ways to handle in pure R in your script the output type, so that you could produce svg or pdf by other means in pure R, etc.

posts: 68 France

Thanks Xavi.

What I would like to do in fact, is to put settings in the R script, not in the plugin configuration. Actually, this needs more logic :
- Have a kind of prescript #//Config #//!Config
- RR launches this prescript
- The prescript outputs some values
- Those values are taken by php to run the script

So R calculates from the data the height of the picture then runs the final part of the script with the calculated height.

Just that thinking about it now, it looks a bit overkill. ggsave might be the option to go, I'll see if there is not caching problem.

posts: 68 France

Ok I just saw in the code that this is simply R script used to build the output :

$image_number++; $input_array[$key] = 'png(filename = "' . $rgo . "_$image_number.png" . '", width = ' . $width . ', height = ' . $height . ', units = "' . $units . '", pointsize = ' . $pointsize . ', bg = "' . $bg . '" , res = ' . $res . ')' ;

I understood that actually more or less what it does is just to append some rscript after the main script in order to export the contents (picture, pdf, html), then to show it.

I'look with Jyhem how to override this : if there is any output in the rscript, such as for instance png() or ggsave(), use the configuration within the R script instead, but keep the file naming system for caching.

What do you think ?

posts: 68 France

We are thinking now to have a "custom PNG output" option, leaving the R script to do the output (as ggsave or other outputs could be used than just png). Just beforehand, we will inject in the R script a RRname variable, that the user needs to use in the R script in order to name the output file.

To make correspond this :

VariablePageNAme (in R)
"' . $rgo . "_$image_number.png" (in RR php)

In order to inject in the beginning of the Rscript :

  1. PHP injects this before the starting of the script

tikiRRfilename = Variable.defined.in.RR.plugin.by.php.and.injected.in.the script

(...R script...)

ggsave(filename=tikiRRfilename, plot=plot, width=calc.width, height=calc.height, scale=v=calc.scale, units="cm")

posts: 38 France

This is what works for us.

In the params definition
'customoutput' => array( 'required' => false, 'safe' => true, 'name' => tra('Custom output'), 'description' => tra('Write your custom png creation R command. Use tikiRRfilename for value of output. RR does not produce an output file.'), 'filter' => 'int', 'default' => '0', 'options' => array( array('text' => '', 'value' => ''), array('text' => tra('No'), 'value' => '0'), array('text' => tra('Yes'), 'value' => '1'), ), 'advanced' => true, ),

in the function runR()
// Check if the user wants to handle the creation of his custom png if ( isset($params["customoutput"]) && $params["customoutput"]=="1" ) { $image_number = 1; $content .= 'tikiRRfilename < - "' . $rgo . "_$image_number.png" . '"' . "\n"; // Add the user input code at the end $content .= $input . "\n"; } else { // Check if the user requested an svg file or pdf file to be generated instead of the standard png in the wiki page if (isset($_REQUEST['gtype']) && $_REQUEST['gtype']=="svg") { […] $content .= $input . "\n"; } # enf of choice between svg and png }

posts: 1817 Catalan Countries

Thanks Jyhem and Joël, I was thinking in the last weeks that we needed something like this, to allow the user to manage 100% of chart generation and display, etc.

I've added your code enhancements to v0.87, already committed (r48058). Remember Jyhem that you can add your improvements to pluginR yourself , following the same 3 rules that we have in Tiki :-)

PluginR is becoming very versatile with all the improvements addded since August. Nice!

I also added a new page in profile r_test: r_test8, which is a showcase of the usage of this new param: customoutput.

Thanks for all your feedback and code contributions!