更改withProgress()生成的消息框的样式和位置 [英] Change style and position of the message box generated by withProgress()

查看:223
本文介绍了更改withProgress()生成的消息框的样式和位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

withProgress()函数可以生成一个消息框,指示闪亮的应用程序正在运行.但是,该消息位于浏览器的右上角,文本大小较小,这使得该消息不那么引人注目.

The withProgress() function can generate a message box indicating the shiny app is running. But the message is at the top-right conner of the browser with a small text size, which makes the message not that eye-catching.

所以我想知道有什么方法可以更改此框的样式和位置,从而使消息更具表达力.

So I wonder is there any way that I could change the style and the position of this box, so that the message can be more expressive.

这是我的代码的一部分:

Here is a part of my code:

output$plot <- renderPlot({ 
 if (input$button){

 withProgress(
              distributionPolygon(data(),unit="years",colors=c("black","gray30","gray50","gray70","blue3","dodgerblue3","steelblue1","lightskyblue1","red4","indianred3","orange","seagreen4"),main=title(),tpsMax=input$months),
              message = 'Loading...',
              detail = ''
              )
      }
   })

推荐答案

更新

这是更新版本,因此您可以参考此示例,该示例摘自此处

server <- function(input, output) {
  output$plot <- renderPlot({
    input$goPlot # Re-run when button is clicked

    # Create 0-row data frame which will be used to store data
    dat <- data.frame(x = numeric(0), y = numeric(0))

    withProgress(message = 'Making plot', value = 0, {
      # Number of times we'll go through the loop
      n <- 10

      for (i in 1:n) {
        # Each time through the loop, add another row of data. This is
        # a stand-in for a long-running computation.
        dat <- rbind(dat, data.frame(x = rnorm(1), y = rnorm(1)))

        # Increment the progress bar, and update the detail text.
        incProgress(1/n, detail = paste("Doing part", i))

        # Pause for 0.1 seconds to simulate a long computation.
        Sys.sleep(0.1)
      }
    })

    plot(dat$x, dat$y)
  })
}

ui <- shinyUI(basicPage(
  plotOutput('plot', width = "300px", height = "300px"),
  actionButton('goPlot', 'Go plot')
))

shinyApp(ui = ui, server = server)

原始帖子

这也与您之前的问题有关.因此,您可能需要更改进度栏的css样式.如果想获得更出色的css进度栏,请随意玩,并做更多的研究.

Original Post

This is related to your previous question too. So you would probably want to change cssstyle of the progress bar. Feel free to play around and do more research if you want a fancier css progress bar.

注意:在计算过程中,我还禁用了按钮,因此用户不会多次单击按钮,从而迫使计算重复进行.您可以进一步查看shinyjs以获取更多信息.如下图所示,在计算过程中该按钮被禁用.完成后将备份

Note: during the calculations I have also disabled the button so users do not click the button multiple times forcing the computation to repeat itself. You can further look into shinyjs for more information. As you can see in the image below during the computation that button is disabled. It will be back up once it is finished

rm(list = ls())
library(shiny)
library(shinyIncubator)
library(shinyjs)

server <- function(input, output, session) {
  observe({
    if(input$aButton==0) return(NULL)
    withProgress(session, min=1, max=15, expr={
      disable("aButton")
      for(i in 1:20) {
        setProgress(message = 'Finished...',detail = paste0('Number ',i, ':20'))
        Sys.sleep(0.1)
      }
      Sys.sleep(1.5)
    })
    enable("aButton")
  })
}

ui <- fluidPage(
  tags$head(tags$style(".shiny-progress {top: 50% !important;left: 50% !important;margin-top: -100px !important;margin-left: -250px !important; color: blue;font-size: 20px;font-style: italic;}")),
  sidebarPanel(actionButton("aButton", "Let's go!"), width=2),
  useShinyjs(),
  mainPanel(progressInit())
)

shinyApp(ui = ui, server = server)

这篇关于更改withProgress()生成的消息框的样式和位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆