R plot()bg颜色行为在Shiny app中发生变化

时间:2017-09-05 11:09:07

标签: r plot shiny

我已经构建了一个多标签的Shiny应用程序,其中包含一个使用基本plot()函数绘制数据的选项卡。

以下是我的Shiny应用程序的基本版本,其中包含示例图的代码。

    ui <- fluidPage(titlePanel("Example plot() within Shiny App"), 
  sidebarLayout(
    sidebarPanel(), 
    mainPanel(tabsetPanel(type = "tab", 
                          tabPanel("Plot", plotOutput(outputId = "PLOT"))
                          )
              ), 
    fluid = TRUE, position = c("left", "right")
  )
)

server <- function(input, output) {
  output$PLOT <- renderPlot({
    par(bg = "gray")
    plot(rnorm(1000), type = "n")
    x <- par("usr")
    rect(x[1], x[3], x[2], x[4], col = "gray")
    points(rnorm(1000))
  })
}

shinyApp(ui = ui, server = server)

这给出了以下结果: plot within shiny app

我读过的所有内容都表明设置标准杆(bg =&#34;灰色&#34;)应该将背景颜色设置为灰色,但它并不是。似乎有一个默认颜色设置,将背景颜色设置为白色。

我在Shiny应用程序之外测试了相同的代码,我得到了预期的结果。

    par(bg = "gray")
    plot(rnorm(1000), type = "n")
    x <- par("usr")
    rect(x[1], x[3], x[2], x[4], col = "gray")
    points(rnorm(1000))

这给出了预期的结果,如下所示:

same plot produced outside of Shiny app

什么是Shiny中的par(bg =&#34; grey&#34;)语句,以及如何在使用Shiny时控制绘图背景颜色?

我也尝试为应用的renderPlot元素设置样式,但这不起作用。

非常感谢

0 个答案:

没有答案