假设我创建了 10 个selectInput
多图导出的下拉菜单以及这些selectInputs
称为“xaxis_1”,“xaxis_2”,.....,“xaxis_10”
对于单个 1 我可以写:if(!is.null(input$xaxis_1)) { .... do stuff }
当用户未输入任何名称并按提交时停止运行导出,以避免崩溃。
更一般一点,你可以检查一下:
if(!is.null(input[[paste('xaxis', i, sep = '_')]])) { ...}
如何优雅地编写它,以便 1 行代码检查 1:10 输入 [[...]] 中的任何一个是否为空,即 NULL?
输入的数量取决于用户想要每个文件导出多少绘图,因此所有内容都是使用lapply(1:input$nrofplots, function(i) { .... } renderUI
结构,而我的 if 语句需要具有 1:n 相同的灵活性
在如下图所示的情况下,按Initiate export
应该给一个sweetalert
(明白了)说至少缺少 1 个值
这是我在 UI 端使用的一个片段,用于验证用户的输入。
library(shiny)
library(shinyjs)
ui <- fluidPage(
useShinyjs(), # Set up shinyjs
numericInput('axis1','Val 1',1),
numericInput('axis2','Val 2',1),
numericInput('axis3','Val 3',1),
actionButton('Go','Plot')
)
server <- function(input, output, session) {
#Try 1, space, AAA and check what shiny will return
observe(print(input$axis1))
observe({
All_Inputs <- vapply(paste0('axis',1:3),
function(x){isTruthy(input[[x]])},
logical(1))
All_InputsCP <- all(All_Inputs)
shinyjs::toggleState(id="Go", condition = All_InputsCP) #This is to make the button Go able or disable according to condition All_InputsCP #
})
}
shinyApp(ui, server)
我希望它有帮助。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)