我只需要在按下按钮并且满足变量条件时显示 BS 模态。
这是一个简单的应用程序,展示了挑战是什么。我需要在触发时显示 BS 模态num_rows >= 500
,并且触发提交按钮,而不仅仅是触发提交按钮时。
我知道这可以通过conditionalPanel
使用input.slider
作为条件之一来完成,但在我的实际项目中它比这复杂得多,并且 BS 模态/条件面板需要同时依赖于按钮(用户输入)和变量分配在server
.
library(shiny)
library(shinyBS)
data = matrix(rnorm(1000*10, 0, 1), nrow = 1000)
ui <- fluidPage(
fluidRow(
column(width = 4,
sliderInput("slider", "Choose Number of Rows to Display", 0, 1000, value = NULL),
submitButton('Submit'),
bsModal("modalExample", "Yes/No", "submit", size = "small", wellPanel(
p(div(HTML("<strong>Warning: </strong> you have chosen to display a large
number of rows. Are you sure you want to proceed?"))),
actionButton("no_button", "Yes"),
actionButton("yes_button", "No")
))
),
column(width = 8,
tableOutput('data')
)
)
)
server <- shinyServer(function(input, output, server){
observe({
num_rows <- input$slider
if(num_rows >= 500){
#
# ACTIVATE MODAL PANEL
#
observeEvent(input$no_button, {
# Do not show table
})
observeEvent(input$yes_button, {
output$table <- renderTable(data)
})
} else{ # Display table normally if number of rows is less than 500
output$table <- renderTable(data)
}
})
})
shinyApp(ui, server)