Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/39.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
Css 有光泽的铝板可以水平使用吗?_Css_R_Shiny_Shiny Reactivity - Fatal编程技术网

Css 有光泽的铝板可以水平使用吗?

Css 有光泽的铝板可以水平使用吗?,css,r,shiny,shiny-reactivity,Css,R,Shiny,Shiny Reactivity,我正在使用sidebarLayout()开发一个闪亮的应用程序,我希望根据sidebarPanel()中输入的值在mainPanel()中并排显示一个或两个绘图 如果只显示一个绘图,我希望该绘图占据100%的mainPanel()水平空间。但是,如果两个图都要显示,我希望每个图都占mainPanel()空间的50% 我还希望每个特定列的内容占据其自身列中所有可用的水平空间 我试过一些东西 具有包含列和条件面板()的fluidRow()的 但是,我无法实现这一点,因为fluidRow()希望每个

我正在使用sidebarLayout()开发一个闪亮的应用程序,我希望根据sidebarPanel()中输入的值在mainPanel()中并排显示一个或两个绘图

如果只显示一个绘图,我希望该绘图占据100%的mainPanel()水平空间。但是,如果两个图都要显示,我希望每个图都占mainPanel()空间的50%

我还希望每个特定列的内容占据其自身列中所有可用的水平空间

我试过一些东西

  • 具有包含列和条件面板()的fluidRow()的

    • 但是,我无法实现这一点,因为fluidRow()希望每个元素都提供一个宽度参数,而conditionalPanel()似乎不兼容
  • splitLayout()右侧的conditionalPanel()

    • 这仅隐藏右侧,不允许左侧打印占用所有mainPanel()空间
  • 右div中带有display:table单元格的conditionalPanel()

    • 但这与上面1的结果相同
  • 库(ggplot2)
    图书馆(闪亮)
    
    ui具有
    renderUI
    的解决方案:

    library(ggplot2)
    library(shiny)
    
    ui <- fluidPage(
      tags$head(
        tags$style("
                   #col_left {
                     background-color: #ffa;
                   }
                   #col_right {
                     background-color: #faf;
                   }
                   ")
        ), 
    
      sidebarPanel(
        checkboxInput("checkbox", 
                      "View Both", 
                      value = TRUE), 
        width = 2
      ), 
    
      mainPanel(
        uiOutput("plots"), 
        width = 10
      )
        )
    
    server <- shinyServer(function(input, output) {
    
      output$plot_output_1 <- renderPlot({
        ggplot(
          data.frame(x = runif(3), y = rnorm(3)), 
          aes(x = x, y = y)) + 
          geom_point(size = 6)
      })
    
      output$plot_output_2 <- renderPlot({
        ggplot(
          data.frame(x = runif(3), y = rnorm(3)), 
          aes(x = x, y = y)) + 
          geom_point(size = 6)
      })
    
      output$plots <- renderUI({
        if(input$checkbox){
          fluidRow(
            column(6, div(id="col_left", plotOutput("plot_output_1"))),
            column(6, div(id="col_right", plotOutput("plot_output_2")))
          )
        }else{
          fluidRow(
            column(12, div(id="col_left", plotOutput("plot_output_1")))
          )
        }
      })
    })
    
    shinyApp(ui, server)
    
    库(ggplot2)
    图书馆(闪亮)
    用户界面
    
    library(ggplot2)
    library(shiny)
    
    ui <- fluidPage(
      tags$head(
        tags$style("
                   #my_container {
                     display: table;
                     width: 100%;
                   }
    
                   .my_col {
                     display: table-cell;
                   }
    
                   #col_left {
                     background-color: #ffa;
                   }
    
                   #col_right {
                     background-color: #faf;
                   }
                   "
        ), 
    
        tags$script("
          Shiny.addCustomMessageHandler('n_show.onchange', function(value) {
            var col_left = document.getElementById('col_left');
            var col_right = document.getElementById('col_right');
    
            if(value == 'one') {
              col_left.style.width = '100%';
              col_right.style.width = '0%';
            } else {
              col_left.style.width = '50%'; 
              col_right.style.width = '50%';
            }
          });
          "
        )
      ), 
    
      sidebarPanel(
        selectInput(inputId = "n_show", label = "Number of Plots", choices = c("one", "two"), selected = "two"), 
        width = 2
      ), 
    
      mainPanel(
        div(id = "my_container", 
            div(id = "col_left", 
                class = "my_col", 
                plotOutput("plot_output_1")),
            div(id = "col_right", 
                class = "my_col", 
                conditionalPanel("input.n_show == 'two'", 
                                 plotOutput("plot_output_2")))
        ), 
        width = 10
      )
    )
    
    server <- shinyServer(function(input, output, session) {
      output$plot_output_1 <- renderPlot({
        input$n_show
    
        ggplot(
          data.frame(x = runif(3), y = rnorm(3)), 
          aes(x = x, y = y)) + 
          geom_point()
      })
    
      output$plot_output_2 <- renderPlot({
        input$n_show
    
        ggplot(
          data.frame(x = runif(3), y = rnorm(3)), 
          aes(x = x, y = y)) + 
          geom_point()
      })
    
      observeEvent(input$checkbox, {
        session$sendCustomMessage("n_show.onchange", input$n_show)
      })
    })
    
    shinyApp(ui, server)
    
    library(ggplot2)
    library(shiny)
    
    ui <- fluidPage(
      tags$head(
        tags$style("
                   #col_left {
                     background-color: #ffa;
                   }
                   #col_right {
                     background-color: #faf;
                   }
                   ")
        ), 
    
      sidebarPanel(
        checkboxInput("checkbox", 
                      "View Both", 
                      value = TRUE), 
        width = 2
      ), 
    
      mainPanel(
        uiOutput("plots"), 
        width = 10
      )
        )
    
    server <- shinyServer(function(input, output) {
    
      output$plot_output_1 <- renderPlot({
        ggplot(
          data.frame(x = runif(3), y = rnorm(3)), 
          aes(x = x, y = y)) + 
          geom_point(size = 6)
      })
    
      output$plot_output_2 <- renderPlot({
        ggplot(
          data.frame(x = runif(3), y = rnorm(3)), 
          aes(x = x, y = y)) + 
          geom_point(size = 6)
      })
    
      output$plots <- renderUI({
        if(input$checkbox){
          fluidRow(
            column(6, div(id="col_left", plotOutput("plot_output_1"))),
            column(6, div(id="col_right", plotOutput("plot_output_2")))
          )
        }else{
          fluidRow(
            column(12, div(id="col_left", plotOutput("plot_output_1")))
          )
        }
      })
    })
    
    shinyApp(ui, server)