Szukałem tego jak dobrze. Większość ludzi sugerują panel warunkowy tak:
conditionalPanel(
condition="!($('html').hasClass('shiny-busy'))",
img(src="images/busy.gif")
)
Zawsze można dać sobie więcej kontroli i stworzyć manipulację warunkowy (być może w zależności od więcej rzeczy), jak to w swoim ui.R:
div(class = "busy",
p("Calculation in progress.."),
img(src="images/busy.gif")
)
gdzie niektóre JavaScript obsługuje Wyświetlanie i ukrywanie tego Gr:
setInterval(function(){
if ($('html').attr('class')=='shiny-busy') {
$('div.busy').show()
} else {
$('div.busy').hide()
}
},100)
z jakimś dodatkowym css można upewnić się, że zajęty animowany obraz dostaje stałą świetnym miejscu gdzie zawsze będzie widoczny.
W każdym z powyższych przypadków stwierdziłem, że warunek "błyszczący zajęty" jest nieco nieprecyzyjny i niewiarygodny: wskaźnik pokazuje się na ułamek sekundy i znika, gdy trwa obliczanie ... Znalazłem brudne rozwiązanie naprawić ten problem, przynajmniej w moich aplikacjach. Zapraszam do wypróbowania go i być może ktoś mógłby dać wgląd w to, jak i dlaczego to rozwiązuje problem.
W swojej server.R trzeba dodać dwa reactiveValues:
shinyServer(function(input, output, session) {
# Reactive Value to reset UI, see render functions for more documentation
uiState <- reactiveValues()
uiState$readyFlag <- 0
uiState$readyCheck <- 0
następnie, w zależności renderPlot (lub inną funkcję wyjścia, gdzie obliczenia przejść dalej), należy użyć tych wartości reaktywne aby zresetować funkcja:
output$plot<- renderPlot({
if (is.null(input$file)){
return()
}
if(input$get == 0){
return()
}
uiState$readyFlag
# DIRTY HACK:
# Everytime "Get Plot" is clicked we get into this function
# In order for the ui to be able show the 'busy' indicator we
# somehow need to abort this function and then of course seamlessly
# call it again.
# We do this by using a reactive value keeping track of the ui State:
# renderPlot is depending on 'readyFlag': if that gets changed somehow
# the reactive programming model will call renderPlot
# If readyFlag equals readyCheck we exit the function (= ui reset) but in the
# meantime we change the readyFlag, so the renderHeatMap function will
# immediatly be called again. At the end of the function we make sure
# readyCheck gets the same value so we are back to the original state
isolate({
if (uiState$readyFlag == uiState$readyCheck) {
uiState$readyFlag <- uiState$readyFlag+1
return(NULL)
}
})
isolate({plot <- ...})
# Here we make sure readyCheck equals readyFlag once again
uiState$readyCheck <- uiState$readyFlag
return(plot)
})
Ten link jest martwy ... –