I am trying to create an interactive dashboard in R with help of flexdashboard and shiny.
I have this table where are seven columns (translated to English): region, year, age, age2, ageMean, jobPosition and wage.
What I try to do is to create 3 dropdown filters with selectInput() for region, year and job position.
Bratislava I 2009 31.93 31.92 30.66 Priemyselná výroba 1510.24
Bratislava I 2009 31.93 31.92 30.66 Dodávka elektriny, plynu, pary a studeného vzduchu 1506.14
Bratislava I 2009 31.93 31.92 30.66 Dodávka vody, čistenie a odvod odpadových vôd, odpady a služby odstraňovania odpadov 911.0
This is what I did for now ( I am pasting whole RMarkdown, but the table I am showing below is in the script named as "dataset".
---
title: "Title: Bratislava"
output:
flexdashboard::flex_dashboard:
orientation: columns
social: menu
source_code: embed
runtime: shiny
---
{r global, include=FALSE}
# load data in 'global' chunk so it can be shared by all users of the dashboard
library(ggplot2)
library(flexdashboard)
library(tidyverse)
library(tidyquant)
library(readxl)
library(shiny)
birthdata <- read_excel(path = "C:/Users/Dase03/Downloads/mydata.xlsx")
salarydata <- read_excel(path = "C:/Users/Dase03/Downloads/salary.xlsx")
salarydata <- salarydata %>%
gather(jobs, wage, -1:-2)
salarydata <- salarydata %>%
filter(Rok > 2008 & wage > 0 & wage != "D")
birthdata <- birthdata %>%
filter(Rok > 2008)
dataset <- left_join(birthdata, salarydata)
dataset$wage <- as.numeric(dataset$wage)
dataset$Okres <- factor(dataset$Okres)
dataset$Okres <- factor(dataset$Okres, levels = c("Bratislava I", "Bratislava II", "Bratislava III", "Bratislava IV", "Bratislava V"))
view(dataset)
Inputs {.sidebar}
-----------------------------------------------------------------------
{r}
selectInput("x", "Choose a District", choices = unique(dataset$Okres))
selectInput("y", "Choose a Year", choices = unique(dataset$Rok))
selectInput("z", "Choose a Job", choices = unique(dataset$jobs))
Outputs
data
renderPlot({
ggplot(dataset, aes_string(x=input$x, y=input$y)) + geom_bar()
})
However, I cannot make it run as it is showing me the error like this:
:1:12: unexpected symbol 1: Bratislava I ^
I tried to fix it, and it looked it works but the filters where not reactive. Bar chart was not changing (was not interactive so I am sure I am going wrong somewhere.
Is someone please willing to a help a bit how to make it run the dashboard?
The final output would be to use on y-axis metrics like age, age2, ageMean and wage.
Thank you a lot for any advice.