闪亮的温度计符号

时间:2017-08-10 13:56:44

标签: r shiny

我正在使用Shiny创建一个应用程序,并希望包含使用symbols()函数创建的温度计图。我为温度计绘图编写了以下代码,它在RStudio的情节查看器中完美地运行:

symbols(0, thermometers = cbind(0.3, 9, 4.1/9), fg = 2, xlab = NA, ylab = NA, inches = 2.5, axes = F)

但是,当我尝试在Shiny中使用它时,页面上不显示任何内容。这是我的代码:

server = function(input, output, session) { ... (not needed for this plot) } ui = fluidPage( tags$div(id="thermometer", style = "height:600px;", symbols(0, thermometers = cbind(0.3, 9, 4.1/9), fg = 2, xlab = NA, ylab = NA, inches = 2.5, axes = F)) ) shinyApp(ui = ui, server = server)

检查页面显示正在创建div,但温度计不存在。有什么建议吗?

1 个答案:

答案 0 :(得分:2)

为了使绘图出现在Shiny中,您需要创建一个输出服务器,然后在ui中呈现它:

server = function(input, output, session) {
  #... (not needed for this plot)
  output$thermometer <- renderPlot({
    symbols(0, thermometers = cbind(0.3, 9, 4.1/9), fg = 2, xlab = NA, ylab = NA, inches = 2.5)
  })
}
ui = fluidPage(
  tags$div(id="thermometer", style = "height:600px;", plotOutput("thermometer"))
)
shinyApp(ui = ui, server = server)

编辑:根据您的评论,另一种绘图方式可能是:

library(shiny)

server = function(input, output, session) {
  #... (not needed for this plot)
  output$thermometer <- renderPlot({
    symbols(0, thermometers = cbind(0.3, 1, 4.1/9), fg = 2, xlab = NA, ylab = NA, inches = 2.5, yaxt='n', xaxt='n', bty='n')
  })
}
ui = fluidPage(
  tags$div(id="thermometer", style = "height:600px;width:200px;margin:auto", plotOutput("thermometer"))
)
shinyApp(ui = ui, server = server)

这将移除温度计周围的轴和框,使其更加明显。