R Shiny - 适合屏幕的列

问题描述 投票:0回答:1

我的应用程序在屏幕上显示不佳。第一个面板设置为 4 列,绘图输出设置为 8,总共 12,但它们不适合整个屏幕,有什么想法吗?

红色方块是我不想拥有的空白区域。情节应该更广泛。我确实遵守了 12 列的规则,仍然没有得到想要的结果。

library(shiny)
library(tidyverse)
library(rsconnect)
install.packages("DT")
library(DT)

#####Import Data

dat<-read_csv(url("https://www.dropbox.com/s/uhfstf6g36ghxwp/cces_sample_coursera.csv?raw=1"))
dat<- dat %>% select(c("pid7","ideo5","CC18_308a", "gender","educ", "newsint","region"))
dat<-drop_na(dat)

ui <- navbarPage("My Application",
                
                 tabPanel("Page 1",
                          
                          column(4,
                          
                          sliderInput(
                            inputId="points",
                            label="Select",
                            min=1,
                            max=5,
                            value=2)
                            
                          ),
                          
                          column(8,
                          
                            mainPanel(
                            
                              tabsetPanel(
                                tabPanel("Tab1", plotOutput("plot1")),
                                tabPanel("Tab2", plotOutput("plot2"))
                              )
                            )
                          
                          )
                 
                          ),
                 
                 
                 
                 tabPanel("Page 2",
                 
                 column(4,
                        
                        checkboxGroupInput(
                          inputId="checkGroup",
                          label="Gender",
                          #choices = list("1"= 1, "2" = 2),  
                          choices = c(1,2), 
                          selected = NULL)
                  
                             
                 ),
                 
                 column(8,
                        
                        mainPanel(
                          
                        plotOutput("data")
                        )
                        
                 )
                 ),
                 
                 tabPanel("Page 3",
                 
                 column(4,
                   
                        selectInput(
                          
                          inputId = "variable",
                          label="Select Region",
                          choices = c("1", "2", "3", "4")
                          
                          
                        )
                   
                 ),
                 
                 column(8,
                        
                        dataTableOutput(outputId = "table2")
                   
                 )
        )
                 
)
               




server<-function(input,output){
  
  output$plot1 <- renderPlot({
    
    
    
    ggplot(
      filter(dat, ideo5==input$points),
      aes(x=pid7)) +
      geom_bar()
  
    
  })
  
  output$plot2 <- renderPlot({
    
    
    
    ggplot(
      filter(dat, ideo5==input$points),
      aes(x=CC18_308a)) +
      geom_bar() +
      xlab("Trump Support")
    
    
  })  
  
  output$data <- renderPlot({
    
    
    ggplot(
      filter(dat, gender %in% input$checkGroup),
      aes(x=educ, y=pid7)) +
      geom_jitter() +
      geom_smooth(method = lm)
    
    
  })
  
  
  
  output$table2 <- renderDataTable({
    
    datatable(dat, pageLength = 10)
    filter(dat,region == input$variable)
    
    })
  
}
shinyApp(ui,server)

r tabs navbar screen
1个回答
0
投票

这是你想要的吗?

我所做的就是摆脱两个

mainPanel()
。看起来主面板占据了其容器的 75%,如果容器是一个带有
width=8
的列,那么您最终会得到整个页面 75% 的 75%。

library(shiny)
library(tidyverse)
library(rsconnect)
install.packages("DT")
library(DT)

#####Import Data

dat<-read_csv(url("https://www.dropbox.com/s/uhfstf6g36ghxwp/cces_sample_coursera.csv?raw=1"))
dat<- dat %>% select(c("pid7","ideo5","CC18_308a", "gender","educ", "newsint","region"))
dat<-drop_na(dat)

ui <- navbarPage("My Application",
                 
                 tabPanel("Page 1",
                          
                          column(4,
                                 
                                 sliderInput(
                                   inputId="points",
                                   label="Select",
                                   min=1,
                                   max=5,
                                   value=2)
                                 
                          ),
                          
                          column(8,
                                 
                             #    mainPanel(
                                   
                                   tabsetPanel(
                                     tabPanel("Tab1", plotOutput("plot1")),
                                     tabPanel("Tab2", plotOutput("plot2"))
                                   )
                              #   )
                                 
                          )
                          
                 ),
                 
                 
                 
                 tabPanel("Page 2",
                          
                          column(4,
                                 
                                 checkboxGroupInput(
                                   inputId="checkGroup",
                                   label="Gender",
                                   #choices = list("1"= 1, "2" = 2),  
                                   choices = c(1,2), 
                                   selected = NULL)
                                 
                                 
                          ),
                          
                          column(8,
                                 
                               #  mainPanel(
                                   
                                   plotOutput("data")
                              #   )
                                 
                          )
                 ),
                 
                 tabPanel("Page 3",
                          
                          column(4,
                                 
                                 selectInput(
                                   
                                   inputId = "variable",
                                   label="Select Region",
                                   choices = c("1", "2", "3", "4")
                                   
                                   
                                 )
                                 
                          ),
                          
                          column(8,
                                 
                                 dataTableOutput(outputId = "table2")
                                 
                          )
                 )
                 
)





server<-function(input,output){
  
  output$plot1 <- renderPlot({
    
    
    
    ggplot(
      filter(dat, ideo5==input$points),
      aes(x=pid7)) +
      geom_bar()
    
    
  })
  
  output$plot2 <- renderPlot({
    
    
    
    ggplot(
      filter(dat, ideo5==input$points),
      aes(x=CC18_308a)) +
      geom_bar() +
      xlab("Trump Support")
    
    
  })  
  
  output$data <- renderPlot({
    
    
    ggplot(
      filter(dat, gender %in% input$checkGroup),
      aes(x=educ, y=pid7)) +
      geom_jitter() +
      geom_smooth(method = lm)
    
    
  })
  
  
  
  output$table2 <- renderDataTable({
    
    datatable(dat, pageLength = 10)
    filter(dat,region == input$variable)
    
  })
  
}
shinyApp(ui,server)
© www.soinside.com 2019 - 2024. All rights reserved.