【发布时间】:2017-04-04 16:14:20
【问题描述】:
我有一个闪亮的应用程序,我想根据用户输入隐藏或显示一些元素。我试图通过在闪亮中使用conditionalPanel 来做到这一点。但是,它只有在按下提交按钮后才能工作。我想隐藏或显示textInput 元素而不按提交按钮。下面是我尝试过的一个例子。
UI.R
library(shiny)
shinyUI(fluidPage(
titlePanel("submitButton example"),
fluidRow(
column(3, wellPanel(
sliderInput("n", "N:", min = 10, max = 1000, value = 200,
step = 10),
checkboxInput("checkbox", label = "Message", value = FALSE),
conditionalPanel(
condition = "input.checkbox == true",
textInput("text", "Text:", "text here")),
submitButton("Submit")
)),
column(6,
plotOutput("plot1", width = 400, height = 300),
verbatimTextOutput("text")
)
)
))
服务器.R
shinyServer(function(input, output) {
output$plot1 <- renderPlot({
hist(rnorm(input$n))
})
output$text <- renderText({
paste("Input text is:", input$text)
})
})
我想在用户选中 checkbox 后立即显示 textInput 并在取消选中时隐藏它,而不依赖于 submit 按钮。
【问题讨论】: