【发布时间】:2017-08-11 04:57:19
【问题描述】:
我正在构建一个 RShiny 应用程序,其中包括 1 个 renderPlot 调用(在服务器中)及其 1 个相应的 plotOutput 调用(在 ui 中)。但是,在 renderPlot 代码中,有一个来自 ui 的切换开关,用于在两个不同的绘图之间切换。我希望地块有不同的坐标。下面是一个可重现的 RShiny 应用程序,它使用通用图来突出我的问题的各个方面:
selector = c("one", "two")
names(selector) = c("one", "two")
plot.width = 600
plot.height = 600
ui <- fluidPage(
fluidRow(
# Organizes the title of the whole shiny app
# ==========================================
column(width = 12, align = 'center',
h2('NBA Shot Chart and Movement Tracking Application'))
),
fluidRow(
# This coordinates the location of the LHS widgets
# ================================================
column(width = 4, align = 'center',
selectInput(inputId = 'shooter.input', label = 'Select Shooter:', multiple = FALSE,
choices = selector, selected = 'one')),
column(width = 8, align = 'left',
plotOutput('shot.chart', width = plot.width, height = plot.height)
)
)
)
server <- shinyServer(function(input, output) {
# renderPlot for the charts (shot charts and movement charts)
output$shot.chart <- renderPlot({
if(input$shooter.input == "one") {
plot(c(1,2,3,4,5), c(6,7,8,9,10))
}
else {
plot(c(1,2,3,4,5), c(1,1,1,1,1))
}
})
})
shinyApp(ui = ui, server = server)
好的,我的问题与 ui 中 plotOutput 中设置的 plot.width 和 plot.height 参数有关。我希望这些参数针对两个图中的每一个都进行更改。当selectInput设置==“one”时,我希望参数为600和600,当selectInput设置==“two”时,我希望参数为600和800。
有没有人遇到过这个问题,并且知道如何处理它? 谢谢!
【问题讨论】: