Hello everyone!! I am beginner in Shiny. I began with creating simple dashboard of gapminder dataset. But I am not able to make a graph that shows the gains in life expectancy over the years as per the change in the input continent.
library(tidyverse)
library(shiny)
library(shinydashboard)
#>
#> Attaching package: 'shinydashboard'
#> The following object is masked from 'package:graphics':
#>
#> box
library(shinyjs)
#> Warning: package 'shinyjs' was built under R version 4.1.2
#>
#> Attaching package: 'shinyjs'
#> The following object is masked from 'package:shiny':
#>
#> runExample
#> The following objects are masked from 'package:methods':
#>
#> removeClass, show
library(ggthemes)
library(gapminder)
library(janitor)
#>
#> Attaching package: 'janitor'
#> The following objects are masked from 'package:stats':
#>
#> chisq.test, fisher.test
library(plotly)
#>
#> Attaching package: 'plotly'
#> The following object is masked from 'package:ggplot2':
#>
#> last_plot
#> The following object is masked from 'package:stats':
#>
#> filter
#> The following object is masked from 'package:graphics':
#>
#> layout
gapminder<-gapminder %>% clean_names()
ui<-dashboardPage(
skin="red",
dashboardHeader(title="Has our world become more prosperous?",titleWidth = 500),
dashboardSidebar(
width = 250,
br(),
h4("Select the inputs here"),
selectInput("continent","Select the continent",choices=sort(unique(continent$continent))),
selectInput("country","Select the countries",choices = sort(unique(gapminder$country)),multiple=TRUE)),
dashboardBody(
tabsetPanel(
type="tabs",
id="tab_selecetd",
tabPanel(title="Continent-view",
plotOutput("plot2")
)
)
))
#> Error in unique(continent$continent): object 'continent' not found
server<-function(input,output){
observe(print(input$continent))
continent<-reactive({
gapminder %>%
group_by(input$continent,year) %>%
summarise(mean_exp=mean(life_exp))
})
output$plot2<-renderPlot({
ggplot(continent(),aes(year,mean_exp))+
geom_line(size=1.2)+theme_minimal()+
labs(title="Gains in life expectancy continent-wise")+
xlab("Year")+
ylab("Average Life Expectancy")
})
}
shinyApp(ui,server)
#> Error in force(ui): object 'ui' not found
Created on 2022-02-04 by the reprex package (v2.0.1)