History: Profile_r_test13_parse_body
Source of version: 17 (current)
Copy to clipboard
! Unfinished work. Alfa state. Playground with survey/questionnaire data collected through tracker forms, and displayed as survey results. You can apply the profile "Voting System" just after the R_demo profile has been applied, so that the tracker for Voting has id 2, and you will have the tracker created for you to have this example working with minimum extra clicks (until this test13 profile page is properly implemented). The fields numbered (so far only hardcoded here) as f_9, f_10 and f_11, are a few fields from the voting, that hold choices of people for a few positions in the association that does run the theoretical voting process. !!- Fetch data using TrackerList to fetch data (parse body param needed) __Wiki a wiki template__ {trackerlist trackerId=2 fields="9:10:11" list_mode=csv max=4 showpagination="n" tplwiki=r_demo13_template01} __Without a wiki template, and with param list_mode=csv__ {trackerlist trackerId=2 fields="9:10:11" list_mode=csv max=4 showpagination="n"} __With a wiki template, and without param list_mode=csv__ {trackerlist trackerId=2 fields="9:10:11" max=4 showpagination="n" tplwiki=r_demo13_template01} So now that you can generate output from a tracker using a trackerlist plugin, or for more flexibility using the list plugin, then a lot more options become possible with R :-) However, it doesn't work as of July 2015 (Tiki12). See bug report related to param list_mode=csv "plugin trackerlist param list_mode=csv does nothing for me" - https://dev.tiki.org/item5688 !!- Display dummy data using a Barplot (parse body param needed) {R(bg="yellow" parse_body="y" echodebug=1)} abundance <- matrix(c({trackerlist trackerId=2 fields="9:10:11" list_mode=csv max=4 showpagination="n" tplwiki=r_demo13_template01}),ncol=3,byrow=TRUE); abundance; barplot(abundance); {R} In the above the echodebug now shows the body content both pre and post parsing so that it can be checked. !! Fetch data using ajax services and display using sjPlot __(parse body param is NOT needed in this case, since data is fetched form custom url via web services)__. You need to grant anonymous perms to export tracker data from that specific tracker. {RR(bg="yellow" parse_body="n" echodebug=1)} r <- getOption("repos") r["CRAN"] <- "http://ftp.heanet.ie/mirrors/cran.r-project.org/" options(repos=r) install.packages("sjPlot") install.packages("sjmisc") install.packages("qdap") install.packages("stringr") ### EXAMPLE with pre-set data frame by hand marca<-c("opel","renault","renault") model<-c("corsa","laguna","modus") cilindrada<-c(1.2,1.9,1.5) color<-c("blanc","vermell","violeta") cotxes<-data.frame(marca,model,cilindrada,color) cotxes ### FETCH tracker data __using Ajax services__ Use some url such as: ^ http://localhost/tiki-ajax_services.php?controller=tracker&action=export_items&trackerId=2&encoding=UTF-8&separator=%2C&delimitorL=%22&delimitorR=%22&CR=%25%25%25&listfields[]=9&listfields[]=10&listfields[]=11&recordsMax=-1 ^ # If your tiki is not under localhost, adapt the path below for my.file my.file <- "http://localhost/tiki-ajax_services.php?controller=tracker&action=export_items&trackerId=2&encoding=UTF-8&separator=%2C&delimitorL=%22&delimitorR=%22&CR=%25%25%25&listfields[]=9&listfields[]=10&listfields[]=11&recordsMax=-1" my.df <- read.csv(my.file) #colnames(my.df) <- c("f_9", "f_10", "f_11") #unlist(str_split(colnames(my.df), "\\."))[1] #str_split(colnames(my.df), "\\.")[[1]][1] # field name from f_9 in this example #str_split(colnames(my.df), "\\.")[[2]][1] # field name from f_10 in this example #str_split(colnames(my.df), "\\.")[[3]][1] # field name from f_11 in this example # load libraries library(sjPlot) library(sjmisc) # init default theme for plots sjp.setTheme(geom.label.size = 2.5, axis.title.size = .9, axis.textsize = .9) sjp.frq(cotxes$marca) sjp.frq(my.df[1]) # this fails for unknown reason str(my.df) library(stringr) my.df <- set_val_labels(my.df, c(str_split(colnames(my.df), "\\.")[[1]][1], str_split(colnames(my.df), "\\.")[[2]][1], str_split(colnames(my.df), "\\.")[[3]][1])) #summary(my.df) # Get counts from the my.df for the sjp.frq function # Maybe using rpivotTable ? # Package rpivotTable # Make Pivot Tables (as in desktop Office software) using R # See: http://www.magesblog.com/2015/03/pivot-tables-with-r.html ## Install package library(devtools) install_github("ramnathv/htmlwidgets") install_github("smartinsightsfromdata/rpivotTable") ## Load rpivotTable library(rpivotTable) data(mtcars) ## One line to create pivot table rpivotTable(mtcars, rows="gear", col="cyl", aggregatorName="Average", vals="mpg", rendererName="Treemap") # Using Package qdap: [NĂ’PE] # qdap: # "Quantitative Discourse Analysis Package: Bridging the Gap Between Qualitative Data and Quantitative Analysis" #library(qdap) #counts() {RR} See: * https://strengejacke.wordpress.com/2013/07/17/plotting-likert-scales-net-stacked-distributions-with-ggplot-rstats/ * http://strengejacke.de/sjPlot/custplot/