0
我只需要按下按鈕時顯示BS模式和並滿足變量條件。Bootstrap模態多重條件R Shiny
這是一個簡單的應用程序,演示了挑戰是什麼。我需要顯示一個BS模式num_rows >= 500
,並且提交按鈕被觸發,而不僅僅是當提交按鈕被觸發時。
我知道這可能是與使用input.slider
作爲條件之一conditionalPanel
來完成,但是在我的實際項目情況比這要複雜得多,和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)
這是一個側面註解:因爲像'modalDialog'和'showModal' 2016年10月和光澤0.14,有光澤的優惠功能。看到我在這裏發佈的示例http://stackoverflow.com/questions/43408022/fileinput-button-with-selectinput-in-shiny。雖然使用像你這樣的shinyBS庫是絕對好的,但我個人認爲應用程序使用閃亮的本地函數更安全。 – Enzo