R, Shiny, 应用前弹出窗口 [英] R, Shiny, Popup Window before App
问题描述
我正在开发一个闪亮的应用程序,它在启动时访问 MySQL 服务器并从中提取大量数据.这些数据稍后会在应用程序的使用过程中进行过滤.
i am developing a shiny App that accesses a MySQL Server on Launch and pulls a large amount of data from it. This data is later filtered during the use of the App.
由于传输的数据量相当大,第一个查询需要很多时间,这就是为什么我想创建一个对话框/弹出窗口或在应用程序启动时打开的类似内容,并让用户选择预过滤器"的设置,例如仅 2017 年 3 月的数据.
Because of the rather large amounts of data transferred the first query takes a lot of time, this is why i would like to create a Dialog / Popup or something similar that opens at the Launch of the App, and lets the user select Settings for a "pre-filter" e.g. only Data from March 2017.
这可能吗,如果是,怎么做?到目前为止我没有找到任何关于它的信息.
Is this possible and if yes, how to do it? I did not find any info about it so far.
推荐答案
这是实现您想要的一种方法.您只需在服务器函数中执行 showModal(modalDialog())
即可在启动时显示弹出窗口.有了这些知识,通过使用 reactiveVal
和 observeEvent
来获得你想要的结果是相当简单的.
Here is one way to achieve what you want. You can show a pop-up on startup by simply doing showModal(modalDialog())
in your server function. With this knowledge, it is fairly straightforward to get the result you want by using a 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)
这篇关于R, Shiny, 应用前弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!