繁体   English   中英

反应区大小,有光泽

[英]Reactive plot size, 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%")
 )
))

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() )
})

亲爱的,试试这个:

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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM