在某种程度上可能有一个闪亮的反应图大小?
这是一个小例子,我希望它如何运作。但由于反应式表达式不在输出中,因此会出错。
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%")
)
))
server.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() )
})
答案 0 :(得分:5)
亲近,试试这个:
ui <- shinyUI(pageWithSidebar(
headerPanel("Title"),
sidebarPanel(
selectInput("direction", "Choose width:",
choices = c("200", "400"))
),
mainPanel(
plotOutput(outputId = "main_plot", width = "100%"),
plotOutput(outputId = "main_plot2", width = "100%")
)
))
server <- shinyServer(function(input, output) {
x <- 1:10
y <- x^2
output$main_plot <- renderPlot({
plot(x, y)}, height = 200, width = 400)
observe({
output$main_plot2 <- renderPlot({
plot(x, y) }, height = 200, width = as.numeric(input$direction))
})
})
shinyApp(ui=ui,server=server)