Я работаю над приложением Shiny, которое подключается к серверу 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)