【发布时间】:2020-10-30 12:24:51
【问题描述】:
我正在寻找一个闪亮的应用程序,用户可以在其中上传一个文本文件,并可以输入他们想要过滤的术语(因此具有两个特定单词或短语的句子)。然后他们可以下载结果。到目前为止,我的脚本如下所示:
ui <- fluidPage(
titlePanel("Download data"),
sidebarLayout(
sidebarPanel(
fileInput("file1", "Choose .txt file",
multiple = F,
accept = c(".txt")),
textInput('energy_co', 'Name of energy company'),
textInput('asset', 'name of Asset Manager'),
downloadButton("downloadData", "Download")
),
mainPanel(
tableOutput("table")
)
)
)
server <- function(input, output, session) {
options(shiny.maxRequestSize=30*1024^2)
output$table <- renderTable({
req(input$file1)
data <- read_lines(input$file1$datapath)
text_df <- as_data_frame(data)
company_data <- text_df %>%
filter(str_detect(terms, input$asset)) %>%
filter(str_detect(terms, input$energy_co)) %>%
distinct(.)
company_data
})
output$downloadData <- downloadHandler(
filename = function() {
paste(company_data, ".csv", sep = "")
},
content = function(file) {
write.csv(company_data, file1, row.names = FALSE)
}
)
}
shinyApp(ui, server)
我可以上传数据集(一个 .txt 文件),但是当我尝试渲染表格或尝试将结果下载为 csv 时没有任何反应。我认为服务器脚本可能需要反应?任何帮助表示赞赏
【问题讨论】: