我希望能够在grepl
功能中使用conditionalPanel
。
这里是MWE。在这一部分中,我测试了我的输入明确是其中一种可能性。
library(shiny)
ui <- fluidPage(
column(5, wellPanel(
uiOutput("test")
)
),
column(7,
conditionalPanel("input.essai_res == 'first choice.xlsx'",
p("test")
)
)
)
server <- function(input, output) {
output$test <- renderUI({
selectInput("essai_res", h3("Test"), c("first choice.xlsx", "second choice.xlsx"))
})
}
shinyApp(ui = ui, server = server)
例如,我希望能够测试字符串“ first”是否是选择的一部分。
我尝试过
conditionalPanel("grepl('first', input.essai_res)", p("test"))
conditionalPanel("'first'.test(input.essai_res)", p("test"))
第二个我尝试使用JavaScript命令。
在这两种情况下,无论列表中的选择是什么,“ test”总是出现。
为了使“测试”仅在选择的一部分时出现,我该怎么办?
我添加此评论以回答以下有关上下文的问题。选择来自那些命令行:
files_list <- list.files(path = "Data/", pattern = "\\.xlsx$|\\.xlsm$", full.names = TRUE)
files_names <- substring(files_list, 6)
files_list <- as.list(files_list)
names(files_list) <- files_names
if (length(files_list) == 0){files_list <- "No files in the folder \"Data\""}
output$path_res <- renderUI({
selectInput("essai_a", h3("Title"), files_list)
})
[使用正则表达式:"(/first/).test(input.essai_res)
”。
您可以使用includes
,但请注意,它在IE中不起作用:
library(shiny)
ui <- fluidPage(
column(
width = 5, wellPanel(
selectInput("essai_res", h3("Test"), c("first choice.xlsx", "second choice.xlsx"))
)
),
column(
width = 7,
conditionalPanel(
"input.essai_res.includes('first')",
p("test")
)
)
)
server <- function(input, output) {
}
shinyApp(ui = ui, server = server)