只要玩Shiny并且已经爱上它了。但是,如何根据绘制的图表,将reactivePlot/plotOutput组合中的图表设为不同的大小?如何有条件地改变R的Shiny包装中图表的纵横比?
在该第一示例中,我已选择“产率曲线”分析,并获得纵横比我想:
但是,当我选择其他的分析,在这种情况下为热图,它是现在与扭曲它的“收益率曲线”图表相同(单元格应该是正方形,而不是矩形)。
如何变更图表的大小取决于该图已被选中?我试着把高度参数= NA,NULL或“”,但它不喜欢任何这些。
另外,但在同一个应用程序中,如何在sidebarPanel的顶部selectInput和textInputs之间获得一些空格?我试过h4(“”),但不起作用。
这里是我的ui.R:
library(shiny)
shinyUI(pageWithSidebar(
headerPanel(h1("SAGB Relative Value Tool")),
sidebarPanel(
h4("Choose analysis:"),
selectInput("analysis1", "",
choices = c("Yield curve", "Optical asset swap spreads",
"Cheap dear box", "Cheap dear charts", "Switch signaliser",
"Barbells")),
h4(" "),
h4("Yield override:"),
lapply(bondNames, function(x)
textInput(paste(x, "bond"), x, last(sagb$sagb)[x]))
),
mainPanel(
h3(textOutput("AnalysisHeader")),
plotOutput("AnalysisOutput", height = "10in"))
))
,这里是我的server.r
library(shiny)
shinyServer(function(input, output) {
output$AnalysisHeader <- reactiveText(function() {
input$analysis1
})
output$AnalysisOutput <- reactivePlot(function() {
switch(input$analysis1,
"Yield curve" = wo(whichOut = 1),
"Optical asset swap spreads" = wo(whichOut = 2),
"Cheap dear box" = wo(whichOut = 3),
"Cheap dear charts" = wo(whichOut = 4),
"Switch signaliser" = wo(whichOut = 5),
"Barbells" = wo(whichOut = 6)
)
})
})
什么是bondNames? – agstudy
bondNames是调用runApp()的程序中的全局列表变量,其中包含南非政府债券(“SAGB”)市场中12个活跃债券的名称。在这里它用于创建边栏产量覆盖输入(虽然有点不稳定 - 我只是刚刚发现了numericInput,我应该使用for循环而不是lapply,而我的粘贴忽略了sep =“”参数)。无论如何不相关的问题。例如,wo()和sagb $ sagb数据结构也是包含代码的一部分。 –
我第二个问题(如果Rstudio的人想知道有多少人对此功能感兴趣!),[我的情节目前无法阅读](http://i.stack.imgur.com/liY3O.png),但我不能静态设置高度,因为根据动态UI,绘图数量会有所不同... – Kevin