代码之家  ›  专栏  ›  技术社区  ›  pachadotdev

表呈现后将div隐藏在shiny中

  •  0
  • pachadotdev  · 技术社区  · 6 年前

    我正在开发一个闪亮的应用程序,它连接到一个SQL服务器并对用户输入运行一些查询。

    为了向用户显示他们的查询正在运行,我包含了一个带有旋转图标的加载消息,但是当表最终呈现时,我找不到删除该消息的方法。

    这里有一个聚合和启用下载的MWE,但是消息没有被正确隐藏/显示:

    if (!require('pacman')) install.packages('pacman')
    p_load(shiny, shinyjs, dplyr, openxlsx)
    
    vars_g <- c("carb", "cyl", "am")
    
    ui <- fluidPage(
      useShinyjs(),
      title = 'mtcars',
      fluidRow(
        column(3, wellPanel(
          h1("Mtcars"),
          h2("Parameters"),
          radioButtons(
            inputId = "operation", 
            label = "Operation:", 
            choices = c("Count"), 
            selected = c("Count")
          ),
          checkboxGroupInput(
            inputId = "cols_g", 
            label = "Group by:", 
            choices = vars_g
          ),
          hr(),
          downloadButton('download', 'Download')
        )),
        column(9, wellPanel(
          h2("Vista previa"),
          div(id = "see_instructions",
              p('Select some columns on the left side'), 
              p('Then you can download the data in Excel'), 
              align = 'center'
          ),
          div(id = "see_loading",
              h1('Processing...'), 
              align = 'center'
          ),
          div(id = "see_table", 
              conditionalPanel(condition = 'output.table', tableOutput('table'))
          )
        ))
      )
    )
    
    server <- function(input, output, session) {
      data <- reactive({
        hide("see_loading")
        vars_g_2 <- input$cols_g
        if(length(vars_g_2) >= 1) {
          hide("see_instructions")
          if (input$operation == "Count") {
            if (!is.null(input$cols_g)) {
              showElement("see_loading")
              mtcars2 <- mtcars %>% 
                group_by(!!!syms(input$cols_g)) %>% 
                summarise(count = n())
            }
    
            show("see_table")
            hide("see_loading")
          }
    
          return(mtcars2)
        }
      })
    
      output$table <- renderTable({ data() })
    
      outputOptions(output, 'table', suspendWhenHidden = FALSE)
    
      output$download <- downloadHandler(
        filename = function() { "data.xlsx" },
        content = function(filename) {
          write.xlsx(data(), filename)
        },
        contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
      )
    }
    
    shinyApp(ui, server)
    
    0 回复  |  直到 6 年前
    推荐文章