我正在开发一个 Shiny 的应用程序,它在启动时访问 MySQL 服务器并从中提取大量数据。此数据稍后会在应用程序的使用过程中被过滤。
由于传输的数据量很大,第一个查询需要很长时间,这就是为什么我想创建一个对话框/弹出窗口或类似的东西,在应用程序启动时打开,并让用户选择“预过滤器”的设置,例如仅 2017 年 3 月的数据。
这可能吗?如果可以,该怎么做?到目前为止,我没有找到任何关于它的信息。
最佳答案
这是实现您想要的目标的一种方法。您只需在服务器函数中执行 showModal(modalDialog())
即可在启动时显示弹出窗口。有了这些知识,使用 reactiveVal
和 observeEvent
就可以非常简单地获得您想要的结果。
希望对您有所帮助!
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)
关于mysql - R, Shiny ,应用程序之前的弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50326110/