R Shiny : plot with dynamical size

标签 r dynamic plot size shiny

我想要一个动态大小的情节,一切都应该发生在 Shiny 的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”只是为了看情节。

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

最佳答案

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

并且宽度和高度的单位必须是有效的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)
        })
    }
))

关于R Shiny : plot with dynamical size,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22408144/

相关文章:

javascript - QML - 事件发生时动态创建计时器

dynamic - SemanticException 分区规范 {col=null} 包含非分区列

python - matplotlib.pyplot.plotfile() - 如何将多个图形绘制到同一个图形中?

r - 如何在ggplot图中绘制y轴和x轴的刻度和数量?

使用 R reticulate 包重新加载 Python 模块

r - 单元格大于零或无穷大

c - 旧 C 代码转换为 R

在 mcmc 中从 R 从 C 调用 R

jquery - 创建具有唯一 ID 的动态 div - jQuery

r - 在地 block 中嵌入微型地 block