我想使用仅当前面的文本输入已完成(其初始值为“”)时才会出现的条件面板。正确定义条件面板中的条件的正确方法是什么?这是一个可重现的代码:
ui <- pageWithSidebar(
headerPanel("TEST"),
sidebarPanel(
textInput('test', "","")),
mainPanel(
conditionalPanel(condition = "input.test != "" ", #problem is here. I've tried many possibilities (such as input.test > 0) but none have worked
helpText("abc"))
)
)
server <- function(input,output){
}
runApp(list(ui=ui,server=server))
Run Code Online (Sandbox Code Playgroud)
任何意见/建议将不胜感激!
干杯
正如评论中所指出的,将条件更改为"input.test != ''"or'input.test != ""'可以解决在引号内包含引号的问题。
另一个解决方案是更改"input.test.length > 0"有效的条件,因为如果您查看conditionalPanel(如下)的源代码,它只是创建一个属性为条件的div位置。data-display-if考虑到它直接转为 html,可以很好地猜测使用 js 作为条件是可行的。
我本可以阅读文档...来自?conditionalPanel:
condition: A JavaScript expression that will be evaluated repeatedly to
determine whether the panel should be displayed.
conditionalPanel
function (condition, ...)
{
div(`data-display-if` = condition, ...)
}
Run Code Online (Sandbox Code Playgroud)