在shiny中是否有可能实现响应式图表大小?
这里是一个小例子,我希望它能够工作。然而它会报错,因为响应式表达式不在输出中。
ui.R文件中,您可以选择宽度和两个图表输出:
shinyUI(pageWithSidebar(
headerPanel("Title"),
sidebarPanel(
selectInput("width", "Choose width:",
choices = c("200", "400"))
),
mainPanel(
plotOutput(outputId = "main_plot", width = "100%"),
plotOutput(outputId = "main_plot2", width = "100%")
)
))
服务器.R文件,第二个图应该具有输入宽度:
shinyServer(function(input, output) {
x <- 1:10
y <- x^2
width <- reactive({
switch(input$direction,
'200' = 200,
'400' = 400)
})
output$main_plot <- renderPlot({
plot(x, y)}, height = 200, width = 400)
output$main_plot2 <- renderPlot({
plot(x, y) }, height = 200, width = width() )
})