0
시스템은 RStudio를 사용하여 시스템을 개발하는 감사 샘플 선택 시스템입니다. 시스템은 다음과 같이 작동합니다.표시되는 출력을 다운로드 할 수 있도록 RShiny에서 다운로드 버튼을 만드는 방법은 무엇입니까?
- 사용자 업로드 Excel 파일 또는 PDF 파일.
- 사용자는 두 개의 라디오 버튼 중 하나를 선택해야합니다. 하나는 '위험도 낮음'이고 다른 하나는 '위험도 높음'입니다.
- 사용자가 '제출'버튼을 클릭하십시오.
- 시스템은 파일의 테이블 행 수에 따라 특정 수의 감사 샘플을 자동으로 선택합니다.
- '낮은 위험도'와 '높은 위험도'에서 선택한 감사 샘플의 수가 다릅니다.
- 선택한 감사 샘플이 표시됩니다.
사용자는 표시된 선택된 감사 샘플을 다운로드 할 수 있습니다.
library(shiny) library(xlsx) library(xlsxjars) library(rJava) library(pdftools) library(tabulizer) ui <- fluidPage( titlePanel("Audit Sample Selection System"), sidebarLayout( sidebarPanel( fileInput("file1", "Choose file", accept = c(".xlsx", ".pdf")), radioButtons("select", "Level of Risk", choices=list("Low Risk" = "low","High Risk" = "high")), actionButton("submit", "Submit") ), mainPanel( tableOutput("contents"), downloadButton("download", "Download") ) ) ) server <- function(input, output){ mydf <- eventReactive(input$submit, { # check for required values (for truthfulness)/ensure the values are available req(input$select) req(input$file1) inFile <- input$file1 if (grepl("*.xlsx",inFile[1]) == TRUE){ file.rename(inFile$datapath, paste(inFile$datapath, ".xlsx", sep = "")) wb <- read.xlsx(paste(inFile$datapath, ".xlsx", sep = ""), 1) nrow(wb) -> rows if (input$select == "low") { # sample for low risk (xlsx) if (rows == 1) { outdf <- wb[sample(rows, 1), ] } else if (rows >= 2 & rows <= 4) { outdf <- wb[sample(rows, 1), ] } else if (rows >= 5 & rows <= 12) { outdf <- wb[sample(rows, 2), ] } else if (rows >= 13 & rows <= 52) { outdf <- wb[sample(rows, 5), ] } else if (rows >= 53 & rows <= 365) { outdf <- wb[sample(rows, 15), ] } else if (rows > 365) { outdf <- wb[sample(rows, 25), ] } } else { # sample for high risk (xlsx) if (rows == 1) { outdf <- wb[sample(rows, 1), ] } else if (rows >= 2 & rows <= 4) { outdf <- wb[sample(rows, 2), ] } else if (rows >= 5 & rows <= 12) { outdf <- wb[sample(rows, 3), ] } else if (rows >= 13 & rows <= 52) { outdf <- wb[sample(rows, 8), ] } else if (rows >= 53 & rows <= 365) { outdf <- wb[sample(rows, 25), ] } else if (rows > 365) { outdf <- wb[sample(rows, 40), ] } } } else if (grepl("*.pdf",inFile[1]) == TRUE) { outtable <- extract_tables(inFile$datapath) outtable[[1]] <- outtable[[1]][-c(1,1),] # Remove header from the table on the first page df <- do.call(rbind, outtable) # Turn matrix into data frame nrow(df) -> rows if (input$select == "low") { # sample for low risk (pdf) if (rows == 1) { outdf <- df[sample(rows, 1), ] } else if (rows >= 2 & rows <= 4) { outdf <- df[sample(rows, 1), ] } else if (rows >= 5 & rows <= 12) { outdf <- df[sample(rows, 2), ] } else if (rows >= 13 & rows <= 52) { outdf <- df[sample(rows, 5), ] } else if (rows >= 53 & rows <= 365) { outdf <- df[sample(rows, 15), ] } else if (rows > 365) { outdf <- df[sample(rows, 25), ] } } else { # sample for high risk (pdf) if (rows == 1) { outdf <- df[sample(rows, 1), ] } else if (rows >= 2 & rows <= 4) { outdf <- df[sample(rows, 2), ] } else if (rows >= 5 & rows <= 12) { outdf <- df[sample(rows, 3), ] } else if (rows >= 13 & rows <= 52) { outdf <- df[sample(rows, 8), ] } else if (rows >= 53 & rows <= 365) { outdf <- df[sample(rows, 25), ] } else if (rows > 365) { outdf <- df[sample(rows, 40), ] } } } else { NULL } }) output$contents <- renderTable({ mydf() }) } shinyApp(ui = ui, server = server)
문제는 내가 '다운로드'버튼을 사용자가 클릭이 표시 선택한 감사 샘플을 다운로드 할 때 그래서 일을 다운로드 버튼을 만드는 방법을 모르는 것입니다.