8

When clicking on drop down arrow, near grouping categories, the corresponding list opens on top of the page. (At first I thought it didn't work at all.). The correct position is next to the arrow, as shown in the picture.

rmarkdown reproducible example:

---
title: "rpivottable_test"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## R Markdown


`r stringi::stri_rand_lipsum(10)`


```{r cars}
library(rpivotTable)

data(mtcars)

```

## Including Plots

You can also embed plots, for example:

```{r pressure, echo=FALSE}
rpivotTable(mtcars,rows="gear", cols=c("cyl","carb"),width="100%", height="400px")
```

enter image description here Here is session Info:

> sessionInfo()
R version 4.1.2 (2021-11-01)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19043)

Matrix products: default

locale:
[1] LC_COLLATE=Greek_Greece.1253 
[2] LC_CTYPE=Greek_Greece.1253   
[3] LC_MONETARY=Greek_Greece.1253
[4] LC_NUMERIC=C                 
[5] LC_TIME=Greek_Greece.1253    

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

other attached packages:
[1] rpivotTable_0.3.0

loaded via a namespace (and not attached):
[1] htmlwidgets_1.5.4 compiler_4.1.2   
[3] fastmap_1.1.0     htmltools_0.5.2  
[5] tools_4.1.2       knitr_1.36       
[7] digest_0.6.28     xfun_0.27        
[9] rlang_0.4.12 
gd047
  • 29,749
  • 18
  • 107
  • 146
  • 3
    Sounds like more relevant at GitHub, noticed package didn't update for past 4 years... – zx8754 Nov 16 '21 at 11:08
  • 1
    This is really sad. I think there is no other way to have an interactive pivot table in R! – Brani Nov 18 '21 at 07:31
  • Maybe it would be worth it to take a look at [esquisse](https://github.com/dreamRs/esquisse) – Roman Nov 18 '21 at 19:48
  • @Roman Thanks, but I need a tool to use in html pages of an intranet website, not an add-in for personal use. – gd047 Nov 19 '21 at 06:54

2 Answers2

3

** WIP answer, will remove when no longer making updates. **

Define the question.

Not exactly clear from the question as currently stated but there is your reproducible example (which demonstrates the incorrect visual format) and then the screenshot visual (which demonstrates the correct visual style).

And for reference, the correct visual style comes from the package vignette here


TLDR - a working answer

Visual proof of solution

---
title: "rpivottable_test"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)

```

## R Markdown


`r stringi::stri_rand_lipsum(10)`


```{r cars, echo}
library(rpivotTable)

data(mtcars)

piv <- rpivotTable(mtcars,rows="gear", cols=c("cyl","carb"), elementId = "pvtTable")
htmlwidgets::saveWidget(piv, "pivot.html")
```

## Including Plots

You can also embed plots, for example:


## Answer

```{r pivot, echo=FALSE}
htmltools::includeHTML('pivot.html')
```

Explanation

  • waves hands vaguely *

So, this is where I fall short and don't really understand the why because at face value, so far everything looks THE SAME.

Things I looked into:

  • The version of htmltools & htmlwidgets
  • The pvtUI & pvtFilterBox divs and css classes
  • The html rendering options of Rmarkdown / knitr
  • Rendering the document with runtime: shiny and wrapping the RpivotTable definition with a renderRpivotTable({ }) call
  • The elementId option because maybe the css got orphaned from an unexpected base elementId??
  • ??
  • Current working theory - invalid style tag from Rmd in Vignette source line 907 is knitted into a link in example Rmd?

vignette source vs rmd source

So. If you have any ideas to contribute on where to look next in Knitr, html, or other topics related to the above - please leave a comment!

sgdata
  • 2,543
  • 1
  • 19
  • 44
  • Why would you post a WIP answer? – Roman Nov 18 '21 at 18:16
  • 5
    @roman Because the solution is valid and helps the asker solve their immediate need - the WIP part is the why which may need to be crowd sourced to find a final and exhaustive reason. – sgdata Nov 18 '21 at 18:40
  • Very good point, @sgoley. Thanks. – Roman Nov 20 '21 at 21:39
  • A major problem is that pages become much larger in size, depending on the number of pivottables and the data in each of them... – gd047 Nov 23 '21 at 08:19
  • @GeorgeDontas Can you edit your question to include that criteria then? Otherwise I believe I answered the current existing question. Actually, part of the issue may be that I removed the `width="100%", height="400px"` arguments. Can you add those back into the rPivotTable generation statement and see if that helps? – sgdata Nov 23 '21 at 12:50
  • Obviously the problem is not just to run the example code. In real conditions the `rmarkdown::render` command often fails to produce the html_document correctly. I am afraid that if the author of the package does not deal with it, no solution will be found. – gd047 Nov 23 '21 at 14:35
  • "In real conditions the `rmarkdown::render` command often fails to produce the html_document correctly" - You are referring to experiences beyond this instance with Rpivot I assume? Just rmarkdown documents in general? – sgdata Nov 23 '21 at 14:57
  • No. I am referring to _some_ rmarkdown documents with rpivots, that -without your workaround- render correctly (except for the dropdown lists, of course), but with it, are not acceptable. Some others though render ok. They are only much larger. – gd047 Nov 23 '21 at 18:00
  • And you are saying that has something to do with the dataset size? Because the current example of mtcars works correctly but isn't representative of your data and therefore your actual problem? Is there another dataset that is more representative? N rows by N columns? Something like that? – sgdata Nov 23 '21 at 18:45
  • @sgoley I'm not sure it's just the dataset size. Maybe coexistence with other elements or widgets is to blame. Here are some of the problems that appear on some pages: The table of contents (TOC) is not shown, some other widgets (like DT) are not displayed, theme colors are wrong, even rpivot itself maybe invisible. Unfortunately I don't have any time right now to deal with it anymore. Thank you for your help. – gd047 Nov 24 '21 at 06:50
  • On my system the solution made the job. Thank you! Just one additional hint: When the filenname in htmlwidgets::saveWidget(piv, "FILENAME.html") included a blank (for example "FILE NAME.html") it failed. So maybe stringr::str_squish("FILE NAME.html") is helpful. – Thomas Buhl Feb 22 '22 at 09:31
3

I wish I found this question when it was asked. Sorry it took so long for you to get an answer.

So the future fix - I'll send the issue and my proposed solution to the Github maintainers of rpivotTable.

For now, you could use

devtools::install_github("fraupflaume/rpivotTable")

I knew it had something to do with the creation of the elements left and right. When I went looking if anyone else had this problem, I found that those that used React JS with pivottable.js filed a ticket in 2018 for a very similar issue. I didn't spend a whole lot of time looking for exactly what they changed, but it did tell me I needed to look at things from that JS package.

So I forked the rpivotTable repo and modified the js file located at

rpivotTable/inst/htmlwidgets/lib/pivottable/pivot.min.js

When the click function is attached it was using position() which gives you the position within the parent. Obviously, when this renders, it was using this as a page position.

I changed that function position() to offset() and wallah! It works.

In my repo, the script is "beautified" (courtesy of Atom's Beautify package). You'll see this change on line 745 in that script if you wanted to look at it.

I used your code for the RMD in the image, but I added names(mtcars)[10] to "George.Dontas."

enter image description here

Kat
  • 15,669
  • 3
  • 18
  • 51
  • I have added you to the contributors for creating our website :-) – gd047 Apr 16 '22 at 07:30
  • Aww! Thanks!! I looked to see if you had any unanswered questions, that's how I found this one. – Kat Apr 16 '22 at 14:03
  • I think found an exception where there is still a problem. Check below your answer on github, Thank you. – gd047 Apr 17 '22 at 05:27
  • 1
    I've added a comment in that repo. I've also updated my repo and it works even with a TOC now. I've thrown a lot at it in an attempt to break it again, but haven't been able to. Please do your $#^$#^ <- worst. :) – Kat Apr 17 '22 at 15:44
  • Thank you so much. I didn't manage to break it either. I have replaced rpivotTable library with yours. P.S.1 I don't think there is an rpivotTable team anymore. I suggest you submit your package, which offers this improvement, to CRAN P.S.2 You didn't have to work on weekend. I feel bad about that. – gd047 Apr 17 '22 at 16:29
  • Here is another rpivottable question that has not been fully answered and concerns me as well. Do you have a solution?https://stackoverflow.com/questions/69008496/how-to-set-size-of-rpivottable-in-rmarkdown-document – gd047 Apr 22 '22 at 18:23
  • 1
    @George Dontas—Το έχω απαντήσει. – Kat Apr 22 '22 at 23:50
  • 1
    What's with all of these crazy bounties?! Thank you. When did this become a bounty question!?! There was another one like this, was that you, too? Thank you if it was; if it wasn't, my thanks go to whomever it was! By the way, I made a few more changes to the `rpivotTable` package (my repo). – Kat Apr 26 '22 at 14:34
  • I've got the whole website moving when the tables expand and reduce their size...however, it pushes the content down and pulls it back up. It does not push and pull content horizontally though. However, I've got controls for the plot sizes, as well. The only time scrolling would be needed is when the table is really wide or your page is really small....where do you want me to put this information... :) – Kat Apr 28 '22 at 03:52