I would like to generate a pivot table from rpivotTable library with a vertical scrollbar to allow viewing long outputs.
The pivot table is generated with knitr in RStudio and is embedded in a flexdashboard template.
I am not using shiny dashboard, for which the issue has already been cleared, mine is just a html dashboard generated with knitr.
Before you give me a minus... I really tried, thinking that maybe a setting is undocumented: my part of the Rmd code looks as follows (scroll in both cases brings no result):
---
title: "Untitled"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
---
```{r setup, include=FALSE}
library(flexdashboard)
library(rpivotTable)
state_table <- data.frame(key=c("CA", "NY", "WA", "ON", "QU"),
name=c("California", "new York", "Washington", "Ontario", "Quebec"),
country=c("USA", "USA", "USA", "Canada", "Canada"))
month_table <- data.frame(key=1:12,
desc=c("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"),
quarter=c("Q1","Q1","Q1","Q2","Q2","Q2","Q3","Q3","Q3","Q4","Q4","Q4"))
prod_table <- data.frame(key=c("Printer", "Tablet", "Laptop"),
price=c(225, 570, 1120))
# Function to generate the Sales table
gen_sales <- function(no_of_recs) { # Generate transaction data randomly
loc <- sample(state_table$key, no_of_recs, replace=T, prob=c(2,2,1,1,1))
time_month <- sample(month_table$key, no_of_recs, replace=T)
time_year <- sample(c(2012, 2013), no_of_recs, replace=T)
prod <- sample(prod_table$key, no_of_recs, replace=T, prob=c(1, 3, 2))
unit <- sample(c(1,2), no_of_recs, replace=T, prob=c(10, 3))
amount <- unit*prod_table[prod,]$price
sales <- data.frame(month=time_month,
year=time_year,
loc=loc,
prod=prod,
unit=unit,
amount=amount)
# Sort the records by time order
sales <- sales[order(sales$year, sales$month),]
row.names(sales) <- NULL
return(sales)
}
# Now create the sales fact table
sales_fact <- gen_sales(100000)
```
Column {data-width=650}
-----------------------------------------------------------------------
### Table
```{r}
library(rpivotTable)
rpivotTable(
sales_fact,
rows = c("year","month"),
cols = c("prod"),
aggregatorName = "Sum",
vals = "amount",
rendererName = "Heatmap",
height = "600px",
overflow = "scroll")
```
Column {data-width=350}
-----------------------------------------------------------------------
### Chart B
```{r}
```
### Chart C
```{r}
```
I will be very thankful for any indication how to achieve vertical scrolling of rpivottable.
This is an easier alternative:
Leave the top portion as this:
---
title: "Untitled"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
---
Then simply add a CSS chunk after your pivot table chunk, like this:
.rpivotTable{ overflow : scroll; }
This header of the chunk can look like this:
{css, Pivot Table CSS, echo = FALSE}
Hope this helps!
your code is not actually reproducible because we don't have "test2". im trying some generic datasets, but they're not even appearing in the table.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With