使用r shiny中的动作按钮下载完整格式的excel文件
我创建了以下闪亮的应用程序
library(shiny)
library(shinyjs)
library(openxlsx)
,一旦导入软件包,我们就会
ui <- fluidPage(
fileInput(inputId = "file", label = "Read File Here", accept = c(".xlsx")),
useShinyjs(), actionButton("showtxt", "Show/Download File"))
server <- function(input, output, session){
server <- function(input, output, session){
observeEvent(input$showtxt,{
tf<-tempdir()
infile<- input$file
wb2 <-openxlsx::loadWorkbook(file = infile$datapath)
df_1<-data.frame("DF"= c(1:3))
addWorksheet(wb = wb2,sheetName = "Parameters1")
writeData(wb2, "Parameters1", df_1, startCol = 1, startRow = 2, rowNames = TRUE)
saveWorkbook(wb2, "File.xlsx") })
# Call Onclick
onclick("showtxt", runjs("window.open('test.xlsx')"))}
shinyApp(ui=ui,server=server)
通过创建Excel Workbook上传的克隆/副本来创建UI和服务器。按下下载时,新的Excel工作簿将具有原始工作簿的所有格式以及添加了新的表格。 该新工作簿保存在包含脚本的文件夹中。默认情况下,我该如何将其转到笔记本电脑下载文件夹。 注意:我已经使用下载处理程序尝试了一下,但是由于某些原因,我想使用一个动作按钮。 我要求某人看看并在这里引导我。先感谢您。
I have created the following shiny App
library(shiny)
library(shinyjs)
library(openxlsx)
Once we import the packages, we create the ui and server as follows
ui <- fluidPage(
fileInput(inputId = "file", label = "Read File Here", accept = c(".xlsx")),
useShinyjs(), actionButton("showtxt", "Show/Download File"))
server <- function(input, output, session){
server <- function(input, output, session){
observeEvent(input$showtxt,{
tf<-tempdir()
infile<- input$file
wb2 <-openxlsx::loadWorkbook(file = infile$datapath)
df_1<-data.frame("DF"= c(1:3))
addWorksheet(wb = wb2,sheetName = "Parameters1")
writeData(wb2, "Parameters1", df_1, startCol = 1, startRow = 2, rowNames = TRUE)
saveWorkbook(wb2, "File.xlsx") })
# Call Onclick
onclick("showtxt", runjs("window.open('test.xlsx')"))}
shinyApp(ui=ui,server=server)
The code works by creating a clone/ copy of the excel workbook uploaded. When the download is pressed, the new excel workbook will have all the formats of the original workbook along with a new sheet added.
This new workbook is saved in the folder containing the script. How can I make it go to my laptops download folder by default.
Note: I have tried this with a download handler but for some reasons, I would like to use an action button.
I request someone to take a look and guide me here. thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论