Thermometer symbol in Shiny

我只是一个虾纸丫 提交于 2020-01-07 07:35:07

问题


I am creating an app using Shiny and would like to include a thermometer plot, created using the symbols() function. I written the following code for my thermometer plot, and it works perfectly fine in the plot viewer in RStudio:

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

However, when I try to use this in Shiny, nothing is displayed on the page. Here's my code:

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)

Inspecting the page shows that the div is being created, but the thermometer is not there. Any suggestions?


回答1:


In order to make a plot appear in Shiny, you need to create an output serverside and then render it in the 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)

EDIT: based on your comment an alternative way of plotting might be:

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)

This removes the axes and box around the thermometer and makes it slightly more visible.



来源:https://stackoverflow.com/questions/45615819/thermometer-symbol-in-shiny

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!