闪亮的情节Gapminder不动

时间:2020-09-11 16:32:38

标签: r shiny

有人可以告诉我为什么我的地块不动吗?我希望每次我更改大陆时,它都会更改以显示不同的大陆。但是情节没有动……年也没有动……求救!下面的代码:

library(shiny)
library(tidyverse)
library(DT)
library(stringr)
library(tools)
library(gapminder)


# Define UI for application that plots features of movies -----------
ui <- fluidPage(
    
    # Application title -----------------------------------------------
    headerPanel("Life Expectancy Over Time"),
    
    # Sidebar layout with a input and output definitions --------------
    sidebarLayout(
        
        # Inputs: Select variables to plot ------------------------------
        sidebarPanel(
            
            # Select variable for y-axis ----------------------------------
            selectInput(inputId = "y",
                        label = "Continent",
                        choices = levels(gapminder$continent),
                        selected = "Asia"),
            
            # Select variable for x-axis ----------------------------------
           
            
            # Select variable for color -----------------------------------
            
            
            # Set alpha level ---------------------------------------------
            sliderInput(inputId = "year",
                        label = "Year:",
                        min = 1952, max = 2007,
                        value = 2002)
            
        ),
        
        # Output --------------------------------------------------------
        mainPanel(
            
            # Show scatterplot --------------------------------------------
            plotOutput(outputId = "lineplot"),
            
            # Show data table ---------------------------------------------
            DT::dataTableOutput(outputId = "continent")
        )
    )
)

# Define server function required to create the scatterplot ---------
server <- function(input, output) {
    
    # Create scatterplot object the plotOutput function is expecting --
    output$lineplot <- renderPlot({
        gapminder2 <- gapminder %>% group_by(year)%>%
            filter(continent=="Africa" | continent=="Americas"|
                       continent=="Asia"| continent=="Europe"|
                   continent == "Oceania")
        ggplot(data = gapminder2, aes(x = year, y = lifeExp,
                                         color = country)) +
            geom_line() +
            labs(x = "Time",
                 y = "Life Expectancy",
                 color = "country")+ theme(legend.position = "none") 
    })
    
    # Print data table if checked -------------------------------------
    output$continent <- DT::renderDataTable({
        DT::datatable(data = gapminder[, 1:6],
                      options = list(pageLength = 10),
                      rownames = FALSE)
    })
}

# Create the Shiny app object ---------------------------------------
shinyApp(ui = ui, server = server)

0 个答案:

没有答案
相关问题