【发布时间】:2019-01-04 13:23:01
【问题描述】:
我有以下闪亮的应用程序
require(shiny)
ui <- fluidPage(
numericInput("num", "num:", 10, min = 1, max = 100),
fileInput(inputId = "upl", multiple = T, label = "upl")
)
server <- function(input, output) {
}
shinyApp(ui, server)
我希望fileInput 上传器仅在numericInput 中指定的文件数量时上传文件。否则它应该给出文件数量错误的消息。
我尝试为此使用shinyjs
//remove existing listener
document.getElementById('upl').outerHTML = document.getElementById('upl').outerHTML;
document.getElementById('upl').addEventListener('change', function() {
if(document.getElementById('upl').files.length == document.getElementById('num').value) {
// something that uploads the files
// I tried to copy the function from the already existing listener, but its anonymous and has no reference so its impossible to copy
} else {
alert('wrong number of files');
}
})
我还没有找到基于条件停止或启动上传的方法,因为input 元素上已经有一个事件监听器,它带有一个我无法复制的匿名函数。
可能有一种我不知道的更简单的方法,知道如何在闪亮中构建条件上传器吗?
【问题讨论】: