I already have one shiny webpage working perfectly, now I need to make it have a dual-axis. I have years on the X-axis, and GDP per Capita on the Y-axis currently. Now my question is how do I make another numerical value show up on the same line graph? I make it so I can show up to 5 countries' GDP line charts at the same time on the graph currently. I am assuming this dual-axis feature code will go in the "server" section of my code? for ease of coding my files would be Aid and GDP_NZ. GDP_NZ is already in the code, I want to add different values from the Aid file ontop of the GDP so I can see multiple values on the line chart through the shiny webapp.
server <- function(input, output) {
output$countryOutput <- renderUI({
#dropdown with select to pick country or can type name of country and choose from there
selectizeInput("countryInput", "Country Name(s) of Interest",
choices = unique(GDP_NZ$Country),
selected = NULL,
multiple = T,
options = list(maxItems = 5,
placeholder = "Pick a Country"))
})
filtered <- reactive({
if (is.null(input$countryInput)) {
return(NULL)
}
GDP_NZ %>%
filter(
Country == input$countryInput
)
})
output$coolplot <- renderPlot({
if (is.null(filtered())) {
return()
}
#axes manipulation and alteration
ggplot(filtered(), aes(x = Year, y = Value, color = Country)) +
geom_line() +
geom_point() +
theme(axis.title.x = element_text(family = "Times", face = "plain", size = 14)) +
theme(axis.title.y = element_text(family = "Times", face = "plain", size = 14)) +
labs(y = "GDP per Capita", x = "Year")
})
output$results <- renderTable({
filtered()
})
}
shinyApp(ui = ui, server = server)