smartinsightsfromdata / rpivotTable

A R wrapper for the great library pivottable
Other
285 stars 71 forks source link

rpivotTable output sent to Rstudio viewer and not to webpage #10

Closed vnijs closed 9 years ago

vnijs commented 9 years ago

Trying out rpivotTable in a shiny app. For some reason it is send the output straight to the Rstudio viewer and not the webpage. It also blocks the other elements of the tabset. Any ideas? Code linked below

https://github.com/mostly-harmless/radiant/tree/shiny11

timelyportfolio commented 9 years ago

Shiny support has not been tested. I hope to get to it over the weekend or next week. I think @smartinsightsfromdata has used in Shiny successfully but not sure if in a tabset.

vnijs commented 9 years ago

The example shiny app works fine. I am using navbarPage and tabsets in my app so maybe there is something there.

smartinsightsfromdata commented 9 years ago

@mostly-harmless I use rpivotTable with an app with navbarpage plus multi-tabs in page (just counted: 11 tab panels distributed in two rows and two tabsetpanels). With no issue whatsoever. Can you share your code please?

smartinsightsfromdata commented 9 years ago

@mostly-harmless This is the UI code:

fluidRow(br(),rpivotTable::rpivotTableOutput('demPivot') )

And this is the server code:

output$demPivot <- renderRpivotTable({
tbl <- model_
rpivotTable(data = tbl
  ,rows="activityname",cols="subfunctionname",
  vals="activityunits", aggregatorName="Sum")
})
vnijs commented 9 years ago

No luck on my end figuring this out yet. My code:

UI: tabPanel("Pivot", rpivotTableOutput("pivotData"))

Server: output$pivotData <- renderRpivotTable({ rpivotTable(data = r_data[[input$dataset]]) })

r_data is a reactiveValue object that has the data.

Just to verify it is not (likely) something on my end I replace the rpivotTable lines with the ones below. Those work fine.

tabPanel("Pivot", dataTableOutput("pivotDataTable")),

output$pivotDataTable <- renderDataTable({ r_data[[input$dataset]] })

Not sure if the line from the js console might be useful:

screen shot 2015-02-06 at 5 17 21 pm

Full code is at:

https://github.com/mostly-harmless/radiant/tree/shiny11

vnijs commented 9 years ago

I made some progress isolating the source of the problem. My ui.R is built using renderUI. The call to rpivottable does not work when I put it in a renderui. However, if I put it directly into ui.R, which I assume is what you to @smartinsightsfromdata, it does works. The file where the tabs are created in my app is linked below in case that is helpful. Any suggestions?

https://github.com/mostly-harmless/radiant/blob/shiny11/inst/base/tools/data/data_ui_and_tabs.R

Note: The output from rpivottable is actually not being shown in Rstudio viewer. The output I was seeing was from an example @timelyportfolio sent me. Sorry for the confusion.

smartinsightsfromdata commented 9 years ago

@mostly-harmless I don't know what to say: it worked for me without problems (nice work by the way, well done!). On the other hand I had (many) problems with the libraries (but this is partly due to RRO - I'm used to it). My sequence of ops was:

  1. build radiant-shiny11 in Rstudio (adding independently any package that was failing the build).
  2. Open in base ui.R and launch it. At least I've got proof with the screenshot!
  3. I wanted to re-try downloading rpivotTable form github (just in case), but when I re-entered into the Rstudio project radiant tried to re-install all the packages failing on some (again, probably due to RRO: I need to install lots of packages as source) and the application did not run. Now I will be busy installing packages from source for a while :)

screen shot 2015-02-07 at 11 45 00

smartinsightsfromdata commented 9 years ago

@mostly-harmless on the other hand, looking at your folders, in www you have a jquery-ui.custom.min.js library already. Assuming it is used by some other part of your code, in some instances the dom will have possibly two jquery-ui scripts, with bad consequences.

smartinsightsfromdata commented 9 years ago

@mostly-harmless Steps tried:

  1. Re-published in github rpivotTable (to be certain that all was ok).
  2. Re-installed rpivotTable
  3. Open in rstudio radiant-shiny11 (I only made one change: I have commented out all of dependencies.R) because of problems with my RRO libraries)
  4. Build radiant package with rstudio
  5. Launched the shiny app (runApp button on rstudio): all OK

I repeated steps 3 to 5 (and just 5. of course) few times with positive results each time. I couldn't see any js error on the page. Of course I haven't navigated every corner of the app (here on safari directly - screen zoomed out to show everything). screen shot 2015-02-07 at 13 02 12

screen shot 2015-02-07 at 13 07 14

vnijs commented 9 years ago

Thanks for looking into this Enzo. Very strange that this works on your machine and not at all on mine. Below is all I see in Chrome or Safari. Could you send me output from sessionInfo() on your machine? What is RRO by the way?

screen shot 2015-02-07 at 8 46 40 am

sessionInfo() R version 3.1.2 (2014-10-31) Platform: x86_64-apple-darwin13.4.0 (64-bit)

locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages: [1] grid stats graphics grDevices utils datasets methods base

other attached packages: [1] radiant_0.1.10 shinyAce_0.2.0 broom_0.3.5.9000 ggvis_0.4
[5] dplyr_0.4.1 tidyr_0.2.0 magrittr_1.5 shiny_0.11
[9] ggplot2_1.0.0 pryr_0.1 lubridate_1.3.3 testthat_0.9.1
[13] rpivotTable_0.1.2.6 rmarkdown_0.4.2 knitr_1.8 markdown_0.7.4
[17] reshape2_1.4.1 brew_1.0-6 AlgDesign_1.1-7.3 wordcloud_2.5
[21] RColorBrewer_1.1-2 vegan_2.2-1 lattice_0.20-29 permute_0.8-3
[25] psych_1.4.8.11 GPArotation_2014.11-1 gridExtra_0.9.1 car_2.0-22

loaded via a namespace (and not attached): [1] assertthat_0.1 cluster_1.15.3 codetools_0.2-10 colorspace_1.2-4 DBI_0.3.1
[6] digest_0.6.8 evaluate_0.5.5 formatR_1.0 gtable_0.1.2 htmltools_0.2.6
[11] htmlwidgets_0.3.2 httpuv_1.3.2 MASS_7.3-37 Matrix_1.1-4 memoise_0.2.1
[16] mgcv_1.8-4 mime_0.2 munsell_0.4.2 nlme_3.1-119 nnet_7.3-8
[21] parallel_3.1.2 plyr_1.8.1 proto_0.3-10 R6_2.0.1 Rcpp_0.11.4
[26] RJSONIO_1.3-0 scales_0.2.4 slam_0.1-32 stringr_0.6.2 tools_3.1.2
[31] xtable_1.7-4 yaml_2.1.13

vnijs commented 9 years ago

I reinstalled rpivotTable from gihtub and now it works. Same package version 0.1.2.6. I don't get it.

2 questions:

  1. It seems the order of factor levels is not maintained when pushed into the browser / pivottable.js.
  2. Is it possible to distinguish factors/character/etc. from numeric variables (e.g., using color)? Numerics are great for averages but, most likely, you wouldn't want them on the row/colum axes.

Anyway, thanks for all the great work on rpivotTable! It really is quite a slick application.

smartinsightsfromdata commented 9 years ago

@mostly-harmless thanks you for using it. In reality I feel a bit of an usurper of fame: frankly all of the merit goes to Nicolas @nicolaskruchten that has developed the pivottable library. Ultimately this is just a wrapper. I'm having some issue in ordering categorical variables too. As far as I understand pivottable works ordering alphabetically any variable except numbers. For example in my project I need to prefix months with 01-Jan etc. to have them ordered properly. In reality you could do some formatting and a different sorting, but from what I saw from Nicolas' examples it is done through additional ad hoc scripting and changes / extension to the renderers. We are sort of limited by accessing to the widget using a single function call from R (let's not forget that pivottable is normally used as a widget in a javascript project where you have more latitude to do things ad hoc). I personally prefer to keep things simple and easy to use. But rest assured that I'll keep an eye on any improvement to the original code and I'll try to pass onto R.

smartinsightsfromdata commented 9 years ago

@mostly-harmless RRO is Revolution R Open. It is significantly faster thanks to intel MKL (on Linux and Windows - but accelerate on Mac) for linear algebra. This is my session info - I'm on OS X yosemite:

sessionInfo()
R version 3.1.2 (2014-10-31)
Platform: x86_64-apple-darwin13.4.0 (64-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_GB.UTF-8

attached base packages:
[1] grid      stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] radiant_0.1.10        shinyAce_0.2.1        broom_0.3.5.9000      ggvis_0.4            
 [5] dplyr_0.4.1           tidyr_0.2.0           magrittr_1.5          shiny_0.11           
 [9] ggplot2_1.0.0         pryr_0.1              lubridate_1.3.3       testthat_0.9.1       
[13] rpivotTable_0.1.2.6   rmarkdown_0.5.1       knitr_1.9             markdown_0.7.4       
[17] reshape2_1.4.1        brew_1.0-6            AlgDesign_1.1-7.3     wordcloud_2.5        
[21] RColorBrewer_1.1-2    vegan_2.2-1           lattice_0.20-29       permute_0.8-3        
[25] psych_1.5.1           GPArotation_2014.11-1 gridExtra_0.9.1       car_2.0-24           

loaded via a namespace (and not attached):
 [1] assertthat_0.1    cluster_2.0.1     codetools_0.2-10  colorspace_1.2-4  DBI_0.3.1        
 [6] digest_0.6.8      evaluate_0.5.5    formatR_1.0       gtable_0.1.2      htmltools_0.2.6  
[11] htmlwidgets_0.3.2 httpuv_1.3.2      lazyeval_0.1.10   lme4_1.1-7        MASS_7.3-37      
[16] Matrix_1.1-5      memoise_0.2.1     mgcv_1.8-4        mime_0.2          minqa_1.2.4      
[21] mnormt_1.5-1      munsell_0.4.2     nlme_3.1-119      nloptr_1.0.4      nnet_7.3-8       
[26] parallel_3.1.2    pbkrtest_0.4-2    plyr_1.8.1        proto_0.3-10      quantreg_5.11    
[31] R6_2.0.1          Rcpp_0.11.4       RJSONIO_1.3-0     scales_0.2.4      slam_0.1-32      
[36] SparseM_1.6       splines_3.1.2     stringr_0.6.2     tools_3.1.2       xtable_1.7-4     
[41] yaml_2.1.13    
vnijs commented 9 years ago

The update to rpivotTable fixed things on my end. Thanks Enzo!