【发布时间】:2018-09-07 02:48:44
【问题描述】:
我正在尝试使用闪亮包中的removeUI() 函数,但我在删除特定元素时遇到了一些困难。下面是这个问题的一个例子,根据help(removeUI) 的例子稍加修改。具体来说,包含textInput( 的注释行被替换为actionButton(。
library(shiny)
ui <- fluidPage(
sidebarPanel(
actionButton("rmv", "Remove UI"),
actionButton("txt", "This is no longer useful")
#textInput("txt", "This is no longer useful")
)
)
# Server logic
server <- function(input, output, session) {
observeEvent(input$rmv, {
removeUI(
selector = "div:has(> #txt)"
)
})
}
# Complete app with UI and server components
shinyApp(ui, server)
虽然textInput() 的组件可以删除,但此方法不适用于使用actionButton() 删除类似组件。我不确定为什么,因为在这种情况下 jQuery 选择器的逻辑看起来是一样的。
我还尝试将 selector = "div:has(> #txt)" 更改为 selector = "button:has(> #txt)",认为 jQuery 搜索将适用于 button 元素,但同样无济于事。
编辑:找到解决方案。用div() 包裹actionButton("txt", "This is no longer useful") 会将操作按钮放入div<> 块中,因此搜索将起作用。
【问题讨论】: