Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 打印输出动态特性_R_Plot_Shiny_Conditional - Fatal编程技术网

R 打印输出动态特性

R 打印输出动态特性,r,plot,shiny,conditional,R,Plot,Shiny,Conditional,我有一个依赖于用户输入的绘图。 根据输入,打印大小将不同 我可以动态控制绘图的高度吗? 我知道在plotOutput()中有一个height参数,但我找不到动态更改它的方法 可复制的例子,当你选择A时,绘图看起来很好,但如果你选择B,它就太高了- library(shiny) library(ggplot2) df1 <- data.frame(x = 1:2000, y = rnorm(2000), type = rep(LETTERS[1:8], 250)) df2 <- da

我有一个依赖于用户输入的绘图。 根据输入,打印大小将不同

我可以动态控制绘图的高度吗? 我知道在
plotOutput()
中有一个height参数,但我找不到动态更改它的方法

可复制的例子,当你选择A时,绘图看起来很好,但如果你选择B,它就太高了-

library(shiny)
library(ggplot2)

df1 <- data.frame(x = 1:2000, y = rnorm(2000), type = rep(LETTERS[1:8], 250))
df2 <- data.frame(x = 1:100, y = rexp (100), type = rep(c('A','B'), 50))

ui <- shinyUI(fluidPage(title = '',
  fluidRow(selectInput("table",'', choices = c('A','B'))),
  fluidRow(plotOutput("my_plot", height = '1000px'))
  )
)

server <- shinyServer(function(input, output) {
  output$my_plot <- renderPlot({
    t <- if(input$table == 'A') df1
    else df2
    ggplot(t) + facet_grid(type~.) +
      geom_point(mapping = aes(x=x, y=y))
  }
  )
})
shinyApp(ui, server)
库(闪亮)
图书馆(GG2)

df1要执行所需操作,需要使用服务器端渲染。UI不知道绘图的内容以及如何动态调整任何内容。它只需获取服务器生成的内容并将其弹出到屏幕上

下面是一段代码,它可以(我想你需要什么)。顺便说一句,我还将“数据”部分放入了它自己的反应函数中。您可以进一步修改我的代码,使像素高度“计算”与硬编码等

library(shiny)
library(ggplot2)

df1 <- data.frame(x = 1:2000, y = rnorm(2000), type = rep(LETTERS[1:8], 250))
df2 <- data.frame(x = 1:100, y = rexp (100), type = rep(c('A','B'), 50))

ui <- shinyUI(fluidPage(title = '',
                        fluidRow(selectInput("table",'', choices = c('A','B'))),
                        fluidRow(uiOutput('myPlotUI'))
)
)

server <- shinyServer(function(input, output) {
  myData <- reactive({
    if (input$table == 'A')
      df1
    else
      df2
  })
  myPlot <- reactive({
    output$myPlot <- renderPlot({
      ggplot(myData()) + facet_grid(type~.) +
        geom_point(mapping = aes(x=x, y=y))
    })
    if (input$table == 'A') {
      plotOutput('myPlot', height = '1000px')
    } else {
      plotOutput('myPlot', height = '250px')
    }
  })
  output$myPlotUI <- renderUI({
    myPlot()
  })
})
shinyApp(ui, server)
库(闪亮)
图书馆(GG2)

非常感谢!我不知道我能在服务器上渲染。完美:)