我想在闪亮的renderPrint()
输出中显示waiter
,但是,默认的rederPrint()
输出太窄,无法完全显示服务员旋转器
我该如何解决这个问题?
谢谢你。
library(shiny)
library(shinydashboard)
library(waiter)
ui <- dashboardPage(
dashboardHeader(title = "Basic dashboard"),
dashboardSidebar(),
dashboardBody(
fluidRow(
waiter::use_waiter(),
column(width = 4,
sliderInput("slider", "Number of observations:", 1, 100, 50),
actionButton("go", "go", class = "btn-warning")
),
column(width = 8,
textOutput("text"),
)
)
)
)
server <- function(input, output) {
output$text <- renderPrint({
observeEvent(input$go, {
w <- waiter::Waiter$new(id = "text")
w$show()
Sys.sleep(3)
on.exit({w$hide()})
output$text <- renderPrint({
cat(paste0(input$slider, " selected."))
})
})
})
}
shinyApp(ui, server)
我们可以通过tagAppendAttributes
向textOutput
添加hight
参数:
library(shiny)
library(shinydashboard)
library(waiter)
ui <- dashboardPage(
dashboardHeader(title = "Basic dashboard"),
dashboardSidebar(),
dashboardBody(
fluidRow(
waiter::use_waiter(),
column(width = 4,
sliderInput("slider", "Number of observations:", 1, 100, 50),
actionButton("go", "go", class = "btn-warning")
),
column(width = 8, tagAppendAttributes(textOutput("text"), style = "height:50px;"))
)
)
)
server <- function(input, output) {
output$text <- renderPrint({
w <- waiter::Waiter$new(id = "text")
w$show()
Sys.sleep(3)
on.exit({w$hide()})
cat(paste0(input$slider, " selected."))
}) |> bindEvent(input$go)
}
shinyApp(ui, server)
PS:请避免嵌套renderXXX
函数