Hey @martin.R ,
Can you please help me with a suggestion...I am trying to webout a Pivot table through R-shiny and trying to export it to excel format.
Can you please help me in the below code how I can make an use of write_xlsx() function instead of write_xlsx2() function.
library(tidyverse)
library(shiny)
library(shinydashboard)
library(rpivotTable)
library(shinyjs)
library(dplyr)
library(rvest)
library(writexl)
library(readxl)
ui <-
dashboardPage(
skin = "green",
dashboardHeader(
title = "Car Data",
titleWidth = 280
),
dashboardSidebar(
width = 280,
sidebarMenu(
menuItem(text = "Output", tabName = "Out1")
),
hr(),
useShinyjs(),
actionButton(inputId = "btnExport", "Export Table")
),
dashboardBody(
tabItems(
tabItem(
tabName = "Out1",
fluidRow(column(width = 10, strong("Data")), align = "center"),
br(),
fluidRow(rpivotTableOutput("Data1"))
)
)
)
)
server <-
function(input, output){
#library(rpivotTable)
output$Data1 <-
renderRpivotTable(
rpivotTable(
data = mtcars
, rows = "cyl"
, cols = "gear"
, height = "780px"
)
)
observeEvent(input$btnExport,{
runjs(
"
var tblhtml=document.getElementsByClassName('pvtRendererArea')[0].innerHTML;
console.log(tblhtml)
//set shiny Input value to read reactively from R
Shiny.setInputValue('tblvar_shiny', tblhtml);
"
)
} )
#save pivot table to xls file
observeEvent(input$tblvar_shiny,
{
minimal_html(input$tblvar_shiny) %>%
html_element("table") %>%
html_table() %>%
as.data.frame() %>%
**write.xlsx2(file="000pivot_final.xls")**
})
}
runApp(
list(ui = ui, server = server) , launch.browser = TRUE
)
I think mostly people will go for JDK installation in order to resolve this, but I just wanted to know can we use write_xlsx() inside shiny.
Thanks