0

I am writing up a shiny app that will produce a stacked column HighChart of Payments by Payment date, stacked by department. In a non-reactive setting this is done by passing a data set to a list, passing the list into a add_series_list in highcharter and the stacked column chart is made. In the reactive setting this is not producing a chart.

This is the server side call to the chart. The temp data set is set from a current month data set, grouped and summarised.

A reactive data_list is created. This is then set through the next bit of code. I didn't put a reactive (although tried it with reactive({}) ) due to:

https://shiny.rstudio.com/reference/shiny/1.0.5/reactiveValues.html

The final bit should output the chart and is based off of:

Highcharter stacked column groupings not using hchart()

output$dailyRevenueChart = renderHighchart({

tempData <- reactive({
  currentMonthdata() %>%
    group_by(PaymentDate, LCO_Indicator) %>%
    summarise(GrossAmount = sum(GrossAmount))
})

data_list <- reactiveValues()

data_list <- 
  tempData() %>% 
    group_by(LCO_Indicator) %>% 
    do(data = list_parse2(.[, c('PaymentDate', 'GrossAmount')])) %>% 
    rename(name = LCO_Indicator) %>% 
    mutate(type = 'column') %>% 
    list_parse()


highchart() %>%
  hc_xAxis(categories = data$PaymentDate) %>%
  hc_add_series_list(isolate(data_list))%>%
  #hc_add_series_list(data_lst2)%>%
  hc_plotOptions(column = list(
    dataLabels = list(enabled = TRUE),
    stacking = "normal",
    enableMouseTracking = TRUE))

})

Here is a Sample data set:

currentMonthData <- tibble::tribble(
   ~PaymentDate,     ~LCO_Indicator, ~TransActionCount, ~Slaes,      ~SalesFreight, ~SalesTax, ~ServiceLabor, ~ServiceMaterials,   ~GrossAmount,
  "2019-01-01",       "Credit",                4L,            -189,             0,      -3.6,             0,                 0,   -192.6,
  "2019-01-01",    "Equipment",                9L,           12286,             0,    250.66,             0,                 0, 12536.66,
  "2019-01-01",   "Equipment",                2L,             9.9,             0,         0,             0,                 0,      9.9,
  "2019-01-02",   "Supply",                2L,             658,             0,     39.48,             0,                 0,   697.48,
  "2019-01-02", "Supply",              190L,               0,             0,         0,       9523.62,            2287.9, 12269.38,
  "2019-01-02",       "Equipment",               76L,        26682.18,              5,   1274.05,             0,                 0, 24639.73
    )

UI Section:

fluidRow(
  column(12,

         tabsetPanel(type = "tabs",
                     tabPanel("Daily Revenue",     highchartOutput("dailyRevenueChart"))

         )

  ) 

I would expect a stacked column highchart output in the UI. I have tested a basic chart in the output to verify the UI components are setup correctly.

astrofunkswag
  • 2,608
  • 12
  • 25
Jabberwockey
  • 349
  • 1
  • 6
  • 18
  • `currentMonthdata()` as you have shown in the example is not reactive, but you are calling it reactivly (`()`), did you mean to do this? – Chabo Jan 04 '19 at 22:15
  • `currentMonthdata()`in the actual code is reactive but I wanted to have a code snippet of data that could be tested with. It is created in the code with: `currentMonthData <- reactive({ data() %>% filter(monthGroup == currentMonthGroup) })` `currentMonthData` get's used in other places in the server component of the module that are displaying correctly. – Jabberwockey Jan 04 '19 at 22:18
  • @Jabberwockey If you don't get help with your issue here on StackOverflow, I can suggest you look for it here: https://shiny.rstudio.com/help/ – raf18seb Jan 07 '19 at 15:02

1 Answers1

0

Working through this setup I discovered the answer to the basic question on this one.

In the UI area of the module, the highchart was not prefaced with the ns component for the module.

The correct UI line should be:

tabPanel("Daily Revenue", highchartOutput(ns("dailyRevenueChart")))

You will notice the ns encapsulates the name of the highchartOutput. The stacking is not correct but the question of why it doesn't show up is now corrected.

Jabberwockey
  • 349
  • 1
  • 6
  • 18