Javascript 如何在有光泽的条件面板内使用str_detect?
我有一个闪亮的应用程序,每当用户在以前的selectInput中选择包含特定单词(而不是确切单词)的字符串时,我都希望出现一个条件面板。以下是我目前拥有的:Javascript 如何在有光泽的条件面板内使用str_detect?,javascript,r,shiny,Javascript,R,Shiny,我有一个闪亮的应用程序,每当用户在以前的selectInput中选择包含特定单词(而不是确切单词)的字符串时,我都希望出现一个条件面板。以下是我目前拥有的: library(shiny) library(tidyverse) ui <- fluidPage( sidebarPanel( selectInput("input1", "Select a word:", choices = c("Word1 some
library(shiny)
library(tidyverse)
ui <- fluidPage(
sidebarPanel(
selectInput("input1",
"Select a word:",
choices = c("Word1 something",
"Word2 something",
"Word3 something",
"Word4 something",
"Word1 nothing")
)
)
)
server <- function(input, output){}
shinyApp(ui, server)
库(闪亮)
图书馆(tidyverse)
ui根据我的评论,这里有另一种方法-
library(shiny)
library(stringr)
ui <- fluidPage(
sidebarPanel(
selectInput("input1",
"Select a word:",
choices = c("Word1 something",
"Word2 something",
"Word3 something",
"Word4 something",
"Word1 nothing")),
uiOutput("cond_input")
)
)
server <- function(input, output, session) ({
output$cond_input <- renderUI({
req(str_detect(input$input1, "Word1"))
selectInput("input2",
"Select another word:",
choices = c("Word10",
"Word11"))
})
})
shinyApp(ui, server)
库(闪亮)
图书馆(stringr)
ui根据我的评论,这里有另一种方法-
library(shiny)
library(stringr)
ui <- fluidPage(
sidebarPanel(
selectInput("input1",
"Select a word:",
choices = c("Word1 something",
"Word2 something",
"Word3 something",
"Word4 something",
"Word1 nothing")),
uiOutput("cond_input")
)
)
server <- function(input, output, session) ({
output$cond_input <- renderUI({
req(str_detect(input$input1, "Word1"))
selectInput("input2",
"Select another word:",
choices = c("Word10",
"Word11"))
})
})
shinyApp(ui, server)
库(闪亮)
图书馆(stringr)
ui您可以使用indexOf()
javascript方法,该方法返回字符串中指定值第一次出现的位置。如果要搜索的值从未出现,则返回-1
library(shiny)
ui <- fluidPage(
sidebarPanel(
selectInput("input1",
"Select a word:",
choices = c("Word1 something",
"Word2 something",
"Word3 something",
"Word4 something",
"Word1 nothing")),
conditionalPanel("input.input1.indexOf('Word1') > -1",
selectInput("input2",
"Select another word:",
choices = c("Word10",
"Word11"))
)
)
)
server <- function(input, output, session) ({
})
shinyApp(ui, server)
库(闪亮)
ui您可以使用indexOf()
javascript方法,该方法返回字符串中指定值第一次出现的位置。如果要搜索的值从未出现,则返回-1
library(shiny)
ui <- fluidPage(
sidebarPanel(
selectInput("input1",
"Select a word:",
choices = c("Word1 something",
"Word2 something",
"Word3 something",
"Word4 something",
"Word1 nothing")),
conditionalPanel("input.input1.indexOf('Word1') > -1",
selectInput("input2",
"Select another word:",
choices = c("Word10",
"Word11"))
)
)
)
server <- function(input, output, session) ({
})
shinyApp(ui, server)
库(闪亮)
ui您可以在条件面板外部使用带有if语句的str\u detect
来创建反应变量吗?然后使用逻辑表达式,如is.null
,或==some value
,检查反应变量并在面板内运行条件语句?一个明显的方法是使用uiOutput
,并将条件放在renderUI
中的服务器端。不过,最好看看是否有办法在ui
端本身执行此操作。您是否可以在条件面板外使用带有if语句的str\u detect
来创建反应变量?然后使用逻辑表达式,如is.null
,或==some value
,检查反应变量并在面板内运行条件语句?一个明显的方法是使用uiOutput
,并将条件放在renderUI
中的服务器端。不过,如果能在ui
端本身找到这样做的方法,那就太好了。