在Shiny中使用uiOutput时,withSpinner不会重复显示

时间:2018-04-19 10:59:10

标签: r shiny

请在反应值出现时(单击操作按钮时)重复显示微调器

UI.R

library(shinycssloaders)
ui <- fluidPage(
  titlePanel("Hello Shiny!"),
  fluidRow(
    column(width = 2, actionButton("actButton", "Click")),
    column(width = 6, withSpinner(uiOutput("htmlExample")))
  )
)

SERVER.R

library(shiny)
library(shinycssloaders)

server<-function(input, output)
{
  getRandomNumber <- function() {
    Sys.sleep(1)
    randamNumber <- runif(n = 1, min = 1e-12, max = .9999999999)
    return(HTML(paste0("<h1>Hai Render Html ................",
                       randamNumber, "<h1>")))
  }
  observeEvent(input$actButton,{
    if (input$actButton == 0)
      return(0)
    isolate({
      output$htmlExample <- renderUI({
        getRandomNumber()
      })
    })
  })
}

1 个答案:

答案 0 :(得分:0)

如何使用busyIndicator来代替包shinysky

以下是一个示例代码:

library(shinysky)
library(shiny)

ui <- fluidPage(
  titlePanel("Hello Shiny!"),
  fluidRow(
    column(width = 2, actionButton("actButton", "Click")),
    busyIndicator(text = 'Rendering HTML....'),
    column(width = 6, uiOutput("htmlExample"))
  )
)

server<-function(input, output)
{
  getRandomNumber <- function() {
    Sys.sleep(2)
    randamNumber <- runif(n = 1, min = 1e-12, max = .9999999999)
    return(HTML(paste0("<h1>Hi Render Html ................",
                       randamNumber, "<h1>")))
  }
  observeEvent(input$actButton,{
    if (input$actButton == 0)
      return(0)
    isolate({
      output$htmlExample <- renderUI({
        getRandomNumber()
      })
    })
  })
}

shinyApp(ui, server)

希望它有所帮助!