【发布时间】:2019-12-04 15:51:23
【问题描述】:
我需要一些关于如何在渲染后重新隐藏闪亮的输出的帮助。下面我提供了一个可重复的示例来解释我的问题。
我希望仅在选择选项 1 和 B 时显示文本 2.2,并且仅在选择选项 2 时显示文本 1。我已经通过在相应设置的条件中包含 conditionalPanel() 来做到这一点。
这可行,但是,一旦文本被渲染,当输入改变时,该文本不会消失。如果用户随后更改输入以选择任何其他选项,即选择选项 2,我希望文本 2.2 消失。
有没有可能用闪亮做到这一点?抱歉,如果以前有人问过这个问题 - 我无法通过搜索找到任何东西 - 非常感谢您的帮助!
library(shiny)
ui <- fluidPage(
sidebarPanel(
selectInput("Input1", label = "Input1", choices = c("Option 1", "Option 2") ),
conditionalPanel(condition = "input.Input1 == 'Option 1'",
selectInput("Input2", label = "Input2",
choices = c("A", "B"))),
),
mainPanel(
tabsetPanel(
tabPanel("Tab 1", textOutput(outputId = "text1")),
tabPanel("Tab 2", textOutput(outputId = "text2.1"), textOutput(outputId = "text2.2") )
)
)
)
server <- function(input, output) {
observe({if(input$Input1 == 'Option 2'){
output$text1 <- renderText("This text only shows for option 2")
}})
output$text2.1 <- renderText("some text")
observe({if(input$Input2 == 'B'){
output$text2.2 <- renderText("Show this only if option 1B is selected")
}})
}
shinyApp(ui, server)
【问题讨论】: