【发布时间】:2021-11-06 15:26:13
【问题描述】:
我创建了一个模块来帮助我接受 1) 一个 excel 文件 2) 工作表名称的文本输入和 3) 范围的文本输入。
我希望能够在应用程序中使用此模块,以便每次单击操作按钮(下面代码中的 AddExcelDataButton)时,它允许我输入不同的文件。我还需要以后能够提取文件的内容。
我在主应用程序中尝试了以下代码,但它向我抛出了以下错误 错误1:用户界面正在链接“按钮内”的所有输入 错误2:我无法弄清楚如何在代码中“访问”或检索文件名。
非常感谢任何以正确方式执行此操作的帮助!
模块代码:
importExceldataUI <- function(importExceldata){
tagList(
tags$div(
HTML(paste0("<b>", "Enter Your Data Here"))
),
tags$div(
fileInput(inputId = "ImportExcelFile",
label = "Excel File",
multiple=FALSE),
style = "display:inline-block; vertical-align:top"
),# end of tags$div for fileInput ImportExcelFile
tags$div(
textInput(inputId = "ExcelSheetName",
label = "Sheet",
value="Data",),
style = "display:inline-block; vertical-align:top"
),#end of tags$Div for texinput-ExcelSheetName
tags$div(
textInput(inputId = "ExcelSheetRange",
label = "Range",
value = "C5:BN1000"),
style = "display:inline-block"
)#end of tags$div for textInput - sheetrange
)
}
importExceldataServer <- function(importExceldata){
moduleServer(importExceldata, function(input, output, session){
})
}
主应用代码
importExceldataApp <- function(){
ui <- fluidPage(
mainPanel(
actionButton(inputId = "AddExcelDataButton", label = "Click here to add Excel Data"),
)#emd pf mainpanel
)
server <- function(input, output, session){
observeEvent(input$AddExcelDataButton, {
insertUI(selector = "#AddExcelDataButton",
ui = importExceldataUI(paste0("file",input$AddExcelDataButton)))
})#end of observeEvent
}
shinyApp(ui, server)
}
importExceldataApp()
【问题讨论】:
标签: r shiny module shiny-server