应用程序之前的R,闪亮,弹出窗口

时间:2018-05-14 08:35:34

标签: mysql r shiny

我正在开发一个闪亮的应用程序,它在启动时访问MySQL服务器并从中提取大量数据。稍后在使用App时过滤此数据。

由于传输的数据量相当大,第一个查询需要花费大量时间,这就是为什么我要创建一个Dialog / Popup或类似的东西,在应用程序的启动时打开,让用户选择“预过滤器”的设置,例如仅限2017年3月的数据。

这是可能的,如果可以,该怎么办?到目前为止,我没有找到任何关于它的信息。

1 个答案:

答案 0 :(得分:1)

这是实现目标的一种方法。只需在服务器功能中执行showModal(modalDialog()),即可在启动时显示弹出窗口。有了这些知识,使用reactiveValobserveEvent来获得所需的结果非常简单。

我希望这有帮助!

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)
相关问题