2017-08-10 26 views
0

我使用Shiny创建应用程序,并希望包含使用symbols()函数创建的温度计图。我写我的温度计情节下面的代码,和它的作品中的情节观众完美的罚款在RStudio:Shiny中的温度计符号

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

然而,当我尝试在闪亮使用这个,没有什么显示在页面上。这里是我的代码:

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)

检查页面显示正在创建的股利,但温度计是不存在的。有什么建议么?

回答

1

为了使情节出现在闪亮,你需要创建一个输出服务器端,然后呈现在用户界面:

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) 

这将删除温度计周围的轴和框,使其稍微更明显。

+0

工作,谢谢。如何“放大”温度计,使其周围没有太多空白区域? –

+0

我不太清楚“放大”是什么意思,但可以通过改变'c(0.3,9,4.1/9)'中的第二个参数使温度计变宽/变窄。我注意到你在原始问题中删除了轴;你可以通过在你的'symbols'命令中加'yaxt ='n',xaxt ='n',bty ='n'来实现。 – Eumenedies