我正在开发一个闪亮的应用程序,它可以在启动时访问 MySQL 服务器并从中提取大量数据。这些数据稍后会在使用应用程序期间被过滤。
由于传输的数据量相当大,第一个查询需要花费很多时间,这就是为什么我想创建一个对话框/弹出窗口或类似的东西,在应用程序启动时打开,并让用户选择设置“预过滤器”例如仅 2017 年 3 月的数据。
这可能吗?如果可以,该怎么做?到目前为止我还没有找到任何有关它的信息。
这是实现您想要的目标的一种方法。您只需执行以下操作即可在启动时显示弹出窗口showModal(modalDialog())
在你的服务器功能中。有了这些知识,通过使用reactiveVal
and an 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)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)