只要玩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