【问题标题】:R Shiny: plot with dynamical sizeR Shiny:动态大小的绘图
【发布时间】:2014-04-19 22:19:02
【问题描述】:

我想要一个动态大小的情节,一切都应该发生在闪亮的UI中。

这是我的代码:

   shinyUI{
      sidebarPanel(
            sliderInput("width", "Plot Width", min = 10, max = 20, value = 15),
            sliderInput("height", "Plot Height", min = 10, max = 20, value = 15)
       )

        mainPanel(
            plotOutput("plot", width="15cm", height="15cm")
        )
    }

我设置“15cm”只是为了看剧情。

我尝试了不同的方法从滑块输入中获取数据并将其带到 plotOutput。我尝试了“input.height”、“input$heigt”,但没有任何效果。

【问题讨论】:

  • 你试过imageOutput吗?

标签: r dynamic plot size shiny


【解决方案1】:

您必须使用服务器端的输入,例如这里是一种解决方案:

并且宽度和高度的单位必须是有效的CSS单位,我不确定“cm”是否有效,使用“%”或“px”(或int,会被强制转换为字符串)以“px”结尾)

library(shiny)

runApp(list(
    ui = pageWithSidebar(
    headerPanel("Test"),
    sidebarPanel(
            sliderInput("width", "Plot Width (%)", min = 0, max = 100, value = 100),
            sliderInput("height", "Plot Height (px)", min = 0, max = 400, value = 400)
       ),
        mainPanel(
            uiOutput("plot.ui")
        )
    ),
    server = function(input, output, session) {

        output$plot.ui <- renderUI({
            plotOutput("plot", width = paste0(input$width, "%"), height = input$height)
        })

        output$plot <- renderPlot({
            plot(1:10)
        })
    }
))

【讨论】:

  • 有没有办法在没有用户输入的情况下做到这一点?绘图可以根据其所在的窗口动态调整大小?
猜你喜欢
  • 1970-01-01
  • 2023-01-12
  • 1970-01-01
  • 2017-07-05
  • 1970-01-01
  • 1970-01-01
  • 2015-03-17
  • 2015-10-31
  • 1970-01-01
相关资源
最近更新 更多