【问题标题】:Reactive plot size, shiny反应性地块大小,有光泽
【发布时间】:2016-01-28 06:19:00
【问题描述】:

是否有可能以某种方式在闪亮中具有反应性绘图大小?

这是一个小例子,我希望它如何工作。尽管响应式表达式不在输出中,但它会给出错误。

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

【问题讨论】:

    标签: r plot shiny


    【解决方案1】:

    你的关闭,试试这个:

    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)
    

    【讨论】:

    • Argh,所以这只是复制粘贴失败...非常感谢您的澄清! :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-02-07
    • 2015-11-11
    • 2020-05-22
    • 2016-03-31
    • 2020-11-22
    • 2020-11-14
    • 2018-02-06
    相关资源
    最近更新 更多