library(shiny)
library(dplyr)
ui <- fluidPage(
dataTableOutput('my_table'),
actionButton('change','Change query')
)
server <- function(input,output,session)
{
# the modal dialog where the user can enter the query details.
query_modal <- modalDialog(
title = "Important message",
selectInput('input_query','Select # cyl:',unique(mtcars$cyl)),
easyClose = F,
footer = tagList(
actionButton("run", "Run query")
)
)
# Show the model on start up ...
showModal(query_modal)
# ... or when user wants to change query
observeEvent(input$change,
{
showModal(query_modal)
})
# reactiveVal to store the dataset
my_dataset <- reactiveVal()
observeEvent(input$run, {
removeModal()
# Your query here
my_data <- mtcars %>% filter(cyl %in% input$input_query)
my_dataset(my_data)
})
# render the output
output$my_table <- renderDataTable(my_dataset())
}
shinyApp(ui,server)
1条答案
按热度按时间vwoqyblh1#
这里有一个方法来实现你想要的。只需执行以下操作,就可以在启动时显示弹出窗口
showModal(modalDialog())
在服务器功能中。有了这些知识,通过使用reactiveVal
和一个observeEvent
.我希望这有帮助!