Shiny withSpinner 隐藏或切换

Shiny withSpinner hide or toggle

我试图在一开始还没有做出选择时隐藏微调器。 这是我迄今为止取得的成就的一个简单示例。

library(shinycssloaders)

ui <- fluidPage(
  selectInput(inputId = "something",
            label = "Select something:",
            choices = c('','None', 'All', 'Some'),
            selected = ''),
  withSpinner(textOutput(outputId = "text")  )
)

server <- function(input, output) {
  observe({
    toggle(id = 'text', condition = F)

    if(nchar(input$something) > 0 ){
      toggle(id = 'text', condition = T)
      Sys.sleep(1)
      output$text <- renderText(paste("You chose ",input$something))
    }
  })
}

shinyApp(ui,server)

选择更改后,微调器会正确显示。不幸的是,一开始切换似乎只适用于文本,而不适用于微调器本身。 我也试过 withSpinner(textOutput(outputId = "text") , id = 'myspin' ) 在 UI 和 toggle(id = 'myspin', condition = F) 在服务器中,但还没有运气。 hide(id = 'text')好像也没效果。

您可以在开始时隐藏容器,然后再次启用它

library(shinycssloaders)
library(shiny)
library(shinyjs)
ui <- fluidPage(
    useShinyjs(),
    selectInput(inputId = "something",
                label = "Select something:",
                choices = c('','None', 'All', 'Some'),
                selected = ''),
    hidden(div(id = 'test', withSpinner(textOutput(outputId = "text"))))
)

server <- function(input, output) {

    observe({
        toggle(id = 'text', condition = FALSE)

        if(nchar(input$something) > 0 ){
            show('test')
            toggle(id = 'text', condition = TRUE)
            Sys.sleep(1)
            output$text <- renderText(paste("You chose ", input$something))
        }
    })
}

shinyApp(ui, server)