Skip to content

Instantly share code, notes, and snippets.

@betterdatascience
Created October 30, 2020 10:51
Show Gist options
  • Save betterdatascience/65223f0dc314a2a65cc49263d5d5af29 to your computer and use it in GitHub Desktop.
Save betterdatascience/65223f0dc314a2a65cc49263d5d5af29 to your computer and use it in GitHub Desktop.
001_powerbi_shiny
library(gapminder)
library(ggplot2)
library(dplyr)
library(shiny)
ui <- fluidPage(
titlePanel("Gapminder explorer", windowTitle = NULL),
plotOutput("line")
)
server <- function(input, output) {
output$line <- renderPlot({
data <- gapminder %>%
group_by(year, continent) %>%
summarise(avgLifeExp = mean(lifeExp))
ggplot(data, aes(x = year, y = avgLifeExp, color = continent)) +
geom_line(size = 1.5) +
ggtitle("Average life expectrancy per continent through time") +
labs(x = "Year", y = "Average life expectancy") +
theme_light() +
theme(
plot.margin = unit(c(2, 1, 1, 1), "cm"),
plot.title = element_text(vjust = 13),
legend.position = c(0.25, 1.07), legend.direction = "horizontal"
)
})
}
shinyApp(ui = ui, server = server)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment