R, Shiny, Popup Window before App

狂风中的少年 提交于 2020-01-06 05:53:52

问题


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.

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.


回答1:


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.

I hope this helps!

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)


来源:https://stackoverflow.com/questions/50326110/r-shiny-popup-window-before-app

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!