【问题标题】:R, Shiny, Popup Window before AppR,闪亮,应用程序前的弹出窗口
【发布时间】:2018-05-14 16:55:23
【问题描述】:

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

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

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

【问题讨论】:

    标签: mysql r shiny


    【解决方案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)
    

    【讨论】:

    • 谢谢,帮了大忙!我还不能投票,因为我没有足够的声誉。不过还是谢谢!
    • 没问题,总是很高兴帮助有这么棒名字的人;)
    • 这是一个非常完美的答案,也正是我所需要的。谢谢!
    猜你喜欢
    • 2017-02-27
    • 2016-08-31
    • 2017-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-23
    • 2017-01-10
    相关资源
    最近更新 更多