我可以动态设置 html class 吗?或者 Shiny 是如何设置 'html'.hasClass('Shiny-busy') 的?

Can I set html class dynamically? Or how does Shiny set 'html'.hasClass('Shiny-busy')?

所以这更像是一个概念性问题,以响应使用

在我闪亮的应用程序上获得 'busy' 通知
conditionalPanel(
        condition="$('html').hasClass('shiny-busy')",
        img(src="images/busy.gif"))  

我在对数据库的初始查询期间获得了要显示的动画 gif,但此后它变得不可预测。如果进行了新的数据库调用,我在第二个条件面板中添加了隐藏输出图:

conditionalPanel(
     condition="!($('html').hasClass('shiny-busy'))",
     plotOutput("Some Graph"))  

设置通过第二次数据拉取工作,但如果进行第三次数据库查询,'Some Graph' 不再隐藏并且 'busy.gif' 不再显示。它确实会在加载新图时闪烁。

所以我的首要问题是:
有没有办法在服务器中显式设置 html class?
或者
How/when Shiny 是否设置了 class 值?

我不打算对问题的其余部分发表评论,但我会回答 "is there a way to explicitly set the html class in server?"

的问题

您可以使用包 shinyjs 到 add/remove/toggle 服务器中 HTML 元素的 class。这是 adding/removing "shiny-busy" class to/form <html> 标签

的示例
library(shiny)
library(shinyjs)

runApp(shinyApp(
  ui = fluidPage(
    useShinyjs(),
    actionButton("add", "add `shiny-busy` class to html tag"),
    actionButton("remove", "remove `shiny-busy` class from html tag")
  ),
  server = function(input, output, session) {
    observeEvent(input$add, {
      shinyjs::addClass(selector = "html", class = "shiny-busy")
    })
    observeEvent(input$remove, {
      shinyjs::removeClass(selector = "html", class = "shiny-busy")
    })    
  }
))