In my Shiny app, I have a ggplot which is supposed to update based on user inputs. However, for one of these inputs I am receiving an error of the form "Error: object [input$myinput] not found" e.g. "Error: object 'Channel' not found" or "Error: object 'UserType' not found" where Channel and UserType are selected input options.
In ui, the input looks like this:
selectInput(inputId = "breakdown",
label = "Breakdown",
choices = c("Channel", "UserType", "Device"),
selected = c("Channel"),
multiple = F)
This works in that I see the input on the UI when running the app.
However, I try to render this ggplot:
output$timeline <- renderPlot({
ggplot(ecom_channel(), aes_string(x = "Date", y = input$kpi_overlay, fill = input$breakdown, group = input$breakdown)) +
geom_area(alpha = 0.3) +
stat_summary(aes(group = 2), fun.y = sum, geom = 'line', size = 2, alpha = 0.5)
})
Since the select input being referenced in input$breakdown
defaults to 'Channel', when I run the app I see:
Error: Object 'Channel' not found
I added a print line to see what the dataframe looks like in the console:
output$timeline <- renderPlot({
print(ecom_channel() %>% glimpse())
ggplot(ecom_channel(), aes_string(x = "Date", y = input$kpi_overlay, fill = input$breakdown, group = input$breakdown)) +
geom_area(alpha = 0.3) +
stat_summary(aes(group = 2), fun.y = sum, geom = 'line', size = 2, alpha = 0.5)
})
Adding that glimpse() line, in my console when I try to run I see:
Listening on http://127.0.0.1:7472
Observations: 0
Variables: 6
Groups: Date [0]
$ Date <date>
$ `input$breakdown` <chr>
$ DailyUsers <dbl>
$ Sessions <dbl>
$ Transactions <dbl>
$ Revenue <dbl>
# A tibble: 0 x 6
# Groups: Date [0]
# … with 6 variables: Date <date>, `input$breakdown` <chr>, DailyUsers <dbl>, Sessions <dbl>, Transactions <dbl>, Revenue <dbl>
Warning: Error in FUN: object 'Channel' not found
183: FUN
182: lapply
181: scales_add_defaults
180: f
179: l$compute_aesthetics
178: f
177: by_layer
176: ggplot_build.ggplot
174: print.ggplot
166: func
164: f
163: Reduce
154: do
153: hybrid_chain
125: drawPlot
111: <reactive:plotObj>
95: drawReactive
82: origRenderFunc
81: output$timeline
1: shiny::runApp
Observations: 28
Variables: 6
Groups: Date [28]
$ Date <date> 2019-12-05, 2019-12-06, 2019-12-07, 2019-12-08, 2019-12-09, 2019-12-10, 2019-12-11, 2019-12-12, 2019-12-13, 2019-12-14, 2019-12-15, 2019-12-16, 2019-12-17, 2019-12…
$ `input$breakdown` <chr> "Channel", "Channel", "Channel", "Channel", "Channel", "Channel", "Channel", "Channel", "Channel", "Channel", "Channel", "Channel", "Channel", "Channel", "Channel",…
$ DailyUsers <dbl> 292704, 265438, 236503, 270920, 326259, 306807, 289131, 277410, 254716, 223153, 249992, 301426, 278872, 259034, 244677, 236412, 197231, 195590, 212663, 165714, 1427…
$ Sessions <dbl> 333310, 302817, 271243, 312109, 374986, 352259, 331171, 316371, 291096, 255558, 286597, 378436, 318979, 294888, 277761, 266630, 224764, 223705, 243362, 189518, 1611…
$ Transactions <dbl> 2812, 2459, 2095, 3087, 3627, 3193, 2959, 2875, 2454, 2095, 2716, 3686, 2635, 2226, 2012, 1728, 1438, 1401, 1592, 973, 686, 970, 1036, 973, 1015, 1289, 1015, 1169
$ Revenue <dbl> 128285.16, 113648.42, 92506.31, 138441.65, 145487.84, 140525.09, 127945.22, 117019.76, 112708.56, 91183.73, 114613.39, 148732.87, 114393.25, 90331.70, 84585.31, 700…
# A tibble: 28 x 6
# Groups: Date [28]
Date `input$breakdown` DailyUsers Sessions Transactions Revenue
<date> <chr> <dbl> <dbl> <dbl> <dbl>
1 2019-12-05 Channel 292704 333310 2812 128285.
2 2019-12-06 Channel 265438 302817 2459 113648.
3 2019-12-07 Channel 236503 271243 2095 92506.
4 2019-12-08 Channel 270920 312109 3087 138442.
5 2019-12-09 Channel 326259 374986 3627 145488.
6 2019-12-10 Channel 306807 352259 3193 140525.
7 2019-12-11 Channel 289131 331171 2959 127945.
8 2019-12-12 Channel 277410 316371 2875 117020.
9 2019-12-13 Channel 254716 291096 2454 112709.
10 2019-12-14 Channel 223153 255558 2095 91184.
# … with 18 more rows
The idea is that I would like my ggplot to break out the selected metric by one of the 3 possible input dimensions of Channel, UserType or Device.
How can I do this?