【发布时间】:2021-07-01 01:44:14
【问题描述】:
我正在尝试调用一个函数来处理用户的请求,然后生成一个 Excel 文件。出于调试目的简化了代码,但我的想法是我需要能够在单击按钮时运行一个函数,但单击“替换”按钮后没有任何反应。
library(shiny)
library(DT)
library(readxl)
library(writexl)
library(openxlsx)
library(plyr)
library(tidyverse)
##################
search_func <- function(user_input) {
hfi <- read_excel("path/to/file", col_names = FALSE, sheet = "One")
hfi_cut <- hfi[-c(1:13),]
hfi_cut[2,1] <- user_input
write_xlsx(hfi_cut, path = "path/to/file/hfi_cut.xlsx")
}
########################################
ui <- fluidPage(
h2("hfi"),
textInput("query", "Watcha wanna replace it with, homie?"),
actionButton("action", "replace"),
downloadButton("dl", "Download")
)
server <- function(input, output, session){
storage <- eventReactive(input$action, {
search_func(input$query)
})
output$dl <- downloadHandler(
filename = function() {paste("Search_Output.xlsx")},
content = function(file) {file.copy(""path/to/file/hfi_cut.xlsx"", file)}
)
}
shinyApp(ui = ui, server = server)
【问题讨论】:
标签: r shiny shinyapps shiny-reactivity