我正在创建一个使用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,但温度计不在那里。有什么建议吗?
发布于 2017-08-10 22:20:36
为了使绘图显示在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)这将移除温度计周围的轴和方框,并使其更容易看到。
https://stackoverflow.com/questions/45615819
复制相似问题