问题描述
因此,这更多是一个概念性问题,以响应使用以下命令在我闪亮的应用程序上收到忙碌"通知:
So this is more of a conceptual question in response to getting a 'busy' notification working on my shiny app using the:
conditionalPanel(
condition="$('html').hasClass('shiny-busy')",
img(src="images/busy.gif"))
我已经获得了一个动画gif,可以在对数据库的初始查询期间显示,但是在那之后它变得不可预测.如果进行了新的数据库调用,我添加了第二个conditionalPanel来隐藏输出图:
I've gotten a animation gif to show during an initial query to a database, but it becomes unpredictable after that. I added in a second conditionalPanel with to hide the output graph if a new database call is made:
conditionalPanel(
condition="!($('html').hasClass('shiny-busy'))",
plotOutput("Some Graph"))
该设置在第二次数据提取中起作用,但是如果进行第三次数据库查询,则"Some Graph"将不再隐藏,并且"busy.gif"将不再显示.加载新图时,它确实会闪烁.
The setup works through the second data pull, but if a third data base query is made, 'Some Graph' no longer hides and 'busy.gif' is no longer shown. It does flash up as a new plot is loaded.
所以我的首要问题是:
有没有一种方法可以在服务器中显式设置html类?
或
Shiny如何/何时设置类值?
So my overarching question is:
Is there a way to explicitly set the html class in server?
OR
How/when does Shiny set the class value?
推荐答案
我不会在其余问题上发表评论,但我将回答是否有一种方法可以在其中明确设置html类"服务器?"
I'm not going to comment on the rest of the question, but I will answer the question of "is there a way to explicitly set the html class in server?"
您可以使用包 shinyjs 来添加/删除/切换HTML元素中的类.服务器.这是添加/删除"shiny-busy"类以形成/形成< html>
标记
You can use the package shinyjs to add/remove/toggle the class of an HTML element in the server. Here's an example of adding/removing the "shiny-busy" class to/form the <html>
tag
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")
})
}
))
这篇关于我可以动态设置html类吗?还是Shiny如何设置'html'.hasClass('Shiny-busy')?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!