首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >闪亮的应用程序上传和下载数据动态不工作

闪亮的应用程序上传和下载数据动态不工作
EN

Stack Overflow用户
提问于 2021-07-09 03:35:33
回答 1查看 297关注 0票数 0

我是超级新的闪亮的应用程序,所以我感谢您的帮助这一点!我的代码目前已被破坏,我不知道为什么。

以下是我的问题:

  1. 如何使这些代码工作?我希望用户上传一个csv文件,在datatable中查看它,然后下载datatable
  2. 如何使用列中的正则表达式过滤行?我希望这个正则表达式应用df[with(df, grepl("\\bDATE\\b|\\b[0-9]{4}-[0-9]{2}-[0-9]{2}\\b|\\b[0-9]{2}-[0-9]{2}\\b|[0-9]{4}\\b", close_notes)),]。您可以假设每个csv文件都将该列作为数据的一部分(在示例中是close_notes)。

谢谢!我的密码在下面。

代码语言:javascript
复制
library(shiny)

ui <- fluidPage(
    sidebarLayout(
        sidebarPanel(
            fileInput("file1", "Choose CSV File",
                      accept = c(
                          "text/csv",
                          "text/comma-separated-values,text/plain",
                          ".csv")
            ),
            tags$hr(),
            checkboxInput("header", "Header", TRUE),
            
            # Button
            downloadButton("downloadData", "Download")
            
        ),
        mainPanel(
            dataTableOutput("contents")
        )
    )
)




server <- function(input, output) {

    output$contents <- renderDataTable({
        # input$file1 will be NULL initially. After the user selects
        # and uploads a file, it will be a data frame with 'name',
        # 'size', 'type', and 'datapath' columns. The 'datapath'
        # column will contain the local filenames where the data can
        # be found.
        inFile <- input$file1
        
        if (is.null(inFile))
            return(NULL)
        
        read.csv(inFile$datapath, header = input$header)
    })
    
    output$downloadData <- downloadHandler(
        filename = function() {
            paste(input$dataset, ".csv", sep = "")
        },
        content = function(file) {
            write.csv(datasetInput(), file, row.names = FALSE)
        }
    )
}

shinyApp(ui, server)
EN

回答 1

Stack Overflow用户

发布于 2021-07-09 04:20:37

尝尝这个

代码语言:javascript
复制
library(shiny)

ui <- fluidPage(
  sidebarLayout(
    sidebarPanel(
      fileInput("file1", "Choose CSV File",
                accept = c(
                  "text/csv",
                  "text/comma-separated-values,text/plain",
                  ".csv")
      ),
      tags$hr(),
      checkboxInput("header", "Header", TRUE),
      
      # Button
      downloadButton("downloadData", "Download")
      
    ),
    mainPanel(
      dataTableOutput("contents")
    )
  )
)

server <- function(input, output) {
  
  datasetInput <- reactive({
    req(input$file1)
    # input$file1 will be NULL initially. After the user selects
    # and uploads a file, it will be a data frame with 'name',
    # 'size', 'type', and 'datapath' columns. The 'datapath'
    # column will contain the local filenames where the data can
    # be found.
    inFile <- input$file1
    
    if (is.null(inFile))
      return(NULL)
    
    read.csv(inFile$datapath, header = input$header)
  })
  
  output$contents <- renderDataTable({
    datasetInput()
  })
  
  output$downloadData <- downloadHandler(
    filename = function() {
      paste("myfile",Sys.Date(), ".csv", sep = "")
    },
    content = function(file) {
      write.csv(datasetInput(), file, row.names = FALSE)
    }
  )
}

shinyApp(ui, server)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68310968

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档