【问题标题】:R Shiny - how to generate this layout with nested rows in column 2R Shiny - 如何使用第 2 列中的嵌套行生成此布局
【发布时间】:2016-05-27 00:11:15
【问题描述】:

我想在“Fluid9”下有两行,但这不起作用。第一行应该有三个图,而第二行应该只有一个图跨越第一行中 3 个图的宽度 (9)。我错过了什么?

我正在尝试获得类似this 的布局(见下面的第二张图片),除了我不需要左侧的滑块。

ui <- shinyUI(fluidPage(
  fluidRow(
    column(12,
      "Fluid12",
         fluidRow(
           column(3,
             "Fluid3",
             numericInput('H_lbv', 'Height - lower bound', 10),
             numericInput('H_ubv', 'Height - upper bound', 21),
             numericInput('D_lbv', 'Diam. - lower bound', 8),
             numericInput('D_ubv', 'Diam. - upper bound', 16),
             numericInput('ro_lbv', 'Dens. - lower bound', 0.3),
             numericInput('ro_ubv', 'Dens. - upper bound', 1.0)
             ),
           column(width = 9,
               "Fluid9",
               fluidRow(
                       column(3,
                              plotOutput("plot")),
                       column(width=3,
                              plotOutput("plot2")),
                       column(width=3,
                              plotOutput("plot3"))
               ), fluidRow( ## I thought this would work to add the second row
                       column(width=9,
                              plotOutput("plot3"))
               )
           )
         )  
      )
  )
 )
)

服务器代码:

server <- function(input, output) {    

        xseq <- reactive({
                x1 <- input$H_lbv - (input$H_ubv - input$H_lbv)/2 # set my x-axis left bound
                x2 <- input$H_ubv + (input$H_ubv - input$H_lbv)/2 # set my x-axis right bound
                # return
                seq(x1, x2, 0.01)
        })

        densities <- reactive({
                dpar <- get.norm.par(p = c(lb, ub), q = c(input$H_lbv, input$H_ubv), plot = FALSE)
                mean <- dpar[1]
                sd <- dpar[2]
                # return
                dnorm(xseq1, mean, sd)
        })        
        densities2 <- reactive({
                dpar2 <- get.norm.par(p = c(lb, ub), q = c(input$D_lbv, input$D_ubv), plot = FALSE)
                mean2 <- dpar2[1]
                sd2 <- dpar2[2]
                # return
                dnorm(xseq2, mean2, sd2)
        })        
        densities3 <- reactive({
                dpar3 <- get.norm.par(p = c(lb, ub), q = c(input$ro_lbv, input$ro_ubv), plot = FALSE)
                mean3 <- dpar3[1]
                sd3 <- dpar3[2]
                # return
                dnorm(xseq3, mean3, sd3)              
        })

        output$plot <- renderPlot({
                plot(xseq1, densities(),
                     col = "darkgreen", xlab="", ylab="Density", type="l",lwd=2, cex=2,
                     main="Height", cex.axis=.8)
        })
        output$plot2 <- renderPlot({
                plot(xseq2, densities2(),
                     col = "darkgreen", xlab="", ylab="Density", type="l",lwd=2, cex=2,
                     main="Diameter", cex.axis=.8)
        })
        output$plot3 <- renderPlot({
                plot(xseq3, densities3(),
                     col = "darkgreen", xlab="", ylab="Density", type="l",lwd=2, cex=2,
                     main="Packing Density", cex.axis=.8)
        })
}

shinyApp(ui = ui, server = server)

【问题讨论】:

    标签: r layout shiny


    【解决方案1】:

    在您的新fluidRow 中,新的最大宽度变为12(它始终是嵌套的)。所以需要把三列的宽度从width=3改为width=4,最后一列从width=9改为width=12。

           column(width = 9,
               "Fluid9",
               fluidRow(
                       column(width=4,
                              plotOutput("plot")),
                       column(width=4,
                              plotOutput("plot2")),
                       column(width=4,
                              plotOutput("plot3"))
               ), fluidRow( ## I thought this would work to add the second row
                       column(width=12,
                              plotOutput("plot3"))
               )
           )
         )  
      )
    

    【讨论】:

    • 我没有意识到这一点。但是,smg 仍然丢失,因为绘图仍未显示(即与我的第一张图片相比没有变化)。
    • 如果您的绘图未渲染,则可能是相关的。有几件事可能是这种情况: 1. 你有两个 plotOutput("plot3")。你只能给他们打电话一次。 2.没有情节4。我假设应该有? 3. 您可能想要重新构建您的流体行和列以获得更好的布局。我认为取出最后一个 plot3 应该可以解决问题。
    • 正确(根据我之前的评论)。每当您在服务器中创建绘图并在 ui 中调用它时,它都会为其创建一个 ID。该 ID 是地块名称。 (所以#plot1、#plot2 等)。在 HTML 页面上,您只能调用一次 ID。不止一次这样做,你就会开始破坏事情。这不是一个闪亮的东西,而是一个 Web 开发的东西。
    • 重复剧情是问题所在!我通过生成我的第四个情节来修复它。谢谢我学到了一些东西!
    猜你喜欢
    • 2020-04-19
    • 2021-11-23
    • 1970-01-01
    • 1970-01-01
    • 2019-03-24
    • 1970-01-01
    • 2018-06-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多