R: fromJSON dynamic keying

Solution 1:

It is an object value, so use [[ instead of $ as $ will literally evaluate

wingspans <- data.frame(savedData[[input$typeSelect]]$Wingspans)

Or can have all the extractions with [[

wingspans <- data.frame(savedData[[input$typeSelect]][["Wingspans"]])

Or if we have purrr loaded, pluck may be useful as well

library(purrr)
wingspans <- data.frame(pluck(savedData, input$typeSelect, "Wingspans"))