R 闪亮-将选项卡面板导出到pdf/excel
我已经创建了一个仪表板(使用shinyUI/shinydashboard包),它有一个使用GT包设计的表 我正在尝试将整个面板/格式化表导出为pdf格式和excel格式,但不知道如何执行此操作 有没有办法达到我的要求 我在下面提到了我正在使用的脚本的简化版本 谢谢 脚本:R 闪亮-将选项卡面板导出到pdf/excel,r,shiny,shinydashboard,shinyapps,gt,R,Shiny,Shinydashboard,Shinyapps,Gt,我已经创建了一个仪表板(使用shinyUI/shinydashboard包),它有一个使用GT包设计的表 我正在尝试将整个面板/格式化表导出为pdf格式和excel格式,但不知道如何执行此操作 有没有办法达到我的要求 我在下面提到了我正在使用的脚本的简化版本 谢谢 脚本: TableA = data.frame(Product = c('iPhone', 'Macbook', 'Airpod', 'Macbook', 'Airpod', 'Macbook', 'iPhone'), East =
TableA = data.frame(Product = c('iPhone', 'Macbook', 'Airpod', 'Macbook', 'Airpod', 'Macbook', 'iPhone'), East = c(1:7), West = c(5:11), North = c(15:21), South = c(24:30))
library(shiny)
library(shinythemes)
library(DT)
library(rhandsontable)
library(tidyverse)
library(tidyquant)
library(knitr)
library(gt)
library(shinycssloaders)
library(shinydashboard)
library(shinyWidgets)
library(shinyscreenshot)
header = dashboardHeader(title = 'Shiny Dashboard', titleWidth = 400)
sidebar = dashboardSidebar( width = 400,
fluidRow(
br(),
div(style="display: inline-block; width: 75px ;", downloadButton(outputId = "PdfDownload", label = NULL, icon = icon("file-pdf"), class = "butt2", #style = "width:100%;"
tags$head(tags$style(".butt2{background-color:white;} .butt2{color: #b30c00 !important;}")))),
div(style="display: inline-block; width: 75px ;", downloadButton(outputId = "ExcelDownload", label = NULL, icon = icon("file-excel"), class = "butt1", #style = "width:100%;"
tags$head(tags$style(".butt1{background-color:white;} .butt1{color: #217346 !important;}")))),
div(style="display: inline-block; width: 75px ;", screenshotButton(selector="#TableC", label = NULL, filename = 'screenshot'))
)
)
body <- dashboardBody(uiOutput("mainpanel"))
ui = dashboardPage(header, sidebar, body)
############
server = function(input, output, session)
{
output$mainpanel = renderUI({
fluidRow(tabBox(width = 250, height = 100,
tabPanel("Apple Sales", value = 'tab1', gt_output(outputId = "TableC")%>% withSpinner(color="#3483CA", type = 1, size = 2)
)
))
})
TableB = as.data.frame(TableA) %>%
gt() %>%
grand_summary_rows(columns = 2:5, fns = list(TotalSales = "sum")) %>%
tab_options(grand_summary_row.background.color = "#DDEBF7") %>%
cols_width(columns = 1 ~ px(1), columns = 2 ~ px(300), everything() ~ px(100)) %>%
tab_spanner(label = "Sales", columns = 3:6)
output$TableC = render_gt(expr = TableB)
}
############
shinyApp(ui = ui, server = server)
TableA=data.frame(产品=c('iPhone','Macbook','Airpod','Macbook','Airpod','Macbook','iPhone'),东=c(1:7),西=c(5:11),北=c(15:21),南=c(24:30))
图书馆(闪亮)
图书馆(shinythemes)
图书馆(DT)
图书馆(rhandsontable)
图书馆(tidyverse)
图书馆(tidyquant)
图书馆(knitr)
图书馆(gt)
图书馆(shinycssloaders)
图书馆(shinydashboard)
图书馆(shinyWidgets)
图书馆(shinyscreenshot)
页眉=仪表板页眉(标题='Shining Dashboard',标题宽度=400)
侧栏=仪表板侧栏(宽度=400,
fluidRow(
br(),
div(style=“display:inline block;width:75px;”,downloadButton(outputId=“PdfDownload”),label=NULL,icon=icon(“file pdf”),class=“butt2”,#style=“width:100%”
tags$head(tags$style(“.butt2{背景色:白色;}.butt2{颜色:#b30c00!重要;}”),
div(style=“display:inline block;width:75px;”,downloadButton(outputId=“excelldownload”,label=NULL,icon=icon(“file excel”),class=“butt1”,#style=“width:100%”
tags$head(tags$style(“.butt1{背景色:白色;}.butt1{颜色:#217346!重要;}”)),
div(style=“display:inline block;width:75px;”,屏幕快照按钮(选择器=“#TableC”,label=NULL,filename='screenshot'))
)
)
主体%withSpinner(color=“#3483CA”,类型=1,大小=2)
)
))
})
TableB=as.data.frame(TableA)%>%
gt()%>%
汇总行(列=2:5,fns=list(TotalSales=“sum”))%>%
tab_选项(grand_summary_row.background.color=“#DDEBF7”)%>%
列宽度(列=1~px(1),列=2~px(300),所有内容()~px(100))%>%
tab_扳手(label=“Sales”,columns=3:6)
输出$TableC=render\u gt(expr=TableB)
}
############
shinyApp(用户界面=用户界面,服务器=服务器)
输出: