闪亮withSpinner隐藏或切换 [英] Shiny withSpinner hide or toggle

查看:267
本文介绍了闪亮withSpinner隐藏或切换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我还未开始做出选择时就试图隐藏微调框. 这是到目前为止我所取得成就的一个简单例子.

I am trying to hide the spinner at the beginning when no choice has been made yet. This is a simple example of what I have achieved so far.

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)

更改选项后,微调器将正确显示.不幸的是,一开始切换似乎只在文本上起作用,而不是在微调框本身上起作用. 我也尝试过 UI中的withSpinner(textOutput(outputId = "text") , id = 'myspin' )和服务器中的toggle(id = 'myspin', condition = F),但还没有运气. hide(id = 'text')似乎也没有作用.

The spinners appear correctly when the choice is changed. Unfortunately, at the beginning the toggle seems to work only on the text, not on the spinner itself. I also tried with withSpinner(textOutput(outputId = "text") , id = 'myspin' ) in the UI and toggle(id = 'myspin', condition = F) in the server, but no luck yet. hide(id = 'text') seems to have no effect either.

推荐答案

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

You can do hide the container at the start and then enable it again

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)

这篇关于闪亮withSpinner隐藏或切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆