I want to be able to use grepl
in a conditionalPanel
function.
Here is a MWE. In this one, I test that my input is explicitely one of the possibilities.
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)
Instead of that, I'd like to be able to test that the string "first" is part of the choice for example.
I tried
conditionalPanel("grepl('first', input.essai_res)", p("test"))
conditionalPanel("'first'.test(input.essai_res)", p("test"))
the second one I did it to try a JavaScript command.
In those 2 cases, whatever the choice in the list, "test" always appears.
What can I do in order to have "test" appears only when "first" is part of the choices?
I add this comment to answer a question below about the context. The choices come from those command lines:
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)
})
You can use includes
but note that it will not work in 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)
With a regex: "(/first/).test(input.essai_res)
".
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.