Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/65.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_Shiny_Shinydashboard - Fatal编程技术网

R 闪亮的仪表板-带有复选框中的值的反应条形图

R 闪亮的仪表板-带有复选框中的值的反应条形图,r,shiny,shinydashboard,R,Shiny,Shinydashboard,根据我的数据,我可以准备一个简单的道奇条形图 geo <- data.frame("year" = c(2018, 2018, 2018, 2019, 2019, 2019, 2020, 2020, 2020), "geo" = c("Europe", "Asia", "America", "Europe", "Asia&

根据我的数据,我可以准备一个简单的道奇条形图

geo <- data.frame("year" = c(2018, 2018, 2018, 2019, 2019, 2019, 2020, 2020, 2020), 
                   "geo" = c("Europe", "Asia", "America", "Europe", "Asia", "America", "Europe", "Asia", "America"), 
                   "sales" = c(100, 150, 200, 500, 500, 500, 1200, 1800, 1200)) 

ggplot(geo, aes(fill=as.factor(year), x=geo, y=sales))+
   geom_bar(position="dodge", stat = "identity")

geo可以这样实现:

  • 您必须根据检查的年份筛选数据集。为此,请使用
    反应式
  • 在renderPlot中,使用reactive返回的数据框进行绘图,只需在
    fill
  • 
    图书馆(闪亮)
    图书馆(shinydashboard)
    地理位置
    
    library(shiny)
    ui <- dashboardPage(
      dashboardHeader(title = "Basic dashboard"),
      dashboardSidebar(),
      dashboardBody(
        # Boxes need to be put in a row (or column)
        fluidRow(
         
          box(plotOutput("plot1", height = 250)),
          
          box(
           
            checkboxGroupInput("checkGroup", label = "Year",                          
                               choices = list("2018"=2018, "2019" = 2019, "2020" = 2020),
                               selected = 2018)
          )
        )
      )
    )
    
    server <- function(input, output) {
    
      output$plot1 <- renderPlot({
        ggplot(geo, aes(fill=as.factor(input$checkGroup), x=geo, y=sales))+
          geom_bar(position="dodge", stat = "identity")
        
      })
    }
    
    shinyApp(ui, server)
    
    
    
        library(shiny)
        library(shinydashboard)
        
        geo <- data.frame("year" = c(2018, 2018, 2018, 2019, 2019, 2019, 2020, 2020, 2020), 
                          "geo" = c("Europe", "Asia", "America", "Europe", "Asia", "America", "Europe", "Asia", "America"), 
                          "sales" = c(100, 150, 200, 500, 500, 500, 1200, 1800, 1200)) 
        
        ui <- dashboardPage(
          dashboardHeader(title = "Basic dashboard"),
          dashboardSidebar(),
          dashboardBody(
            # Boxes need to be put in a row (or column)
            fluidRow(
              
              box(plotOutput("plot1", height = 250)),
              
              box(
                
                checkboxGroupInput("checkGroup", label = "Year",                          
                                   choices = list("2018"=2018, "2019" = 2019, "2020" = 2020),
                                   selected = 2018)
              )
            )
          )
        )
        
        server <- function(input, output) {
          
          dat <- reactive({
            filter(geo, year %in% input$checkGroup)
          })
          
          output$plot1 <- renderPlot({
            ggplot(dat(), aes(fill=as.factor(year), x=geo, y=sales))+
              geom_bar(position="dodge", stat = "identity")
            
          })
        }
        
        shinyApp(ui, server)