0

Attempting to build off of Stack Exchange Question: R Highcharter: tooltip customization

Have a R module (below). That ingests some data and provides the UI including highcharter visualizations.

consolidatedlogModuleUI <- function(id){

  ns <- NS(id)

 tagList(

fluidRow(
  bs4Card(highchartOutput(ns("fundedbydayChart")),
         width = 12,
         collapsible = TRUE)
),
fluidRow(
  bs4TabCard(title = "Consolidated Log",
             elevation = 2,
             width = 12,
             bs4TabPanel(
               tabName = "tab1",
               active = TRUE,
               DT::dataTableOutput(ns("consolidatedlogTable"))
             ),
             bs4TabPanel(
               tabName = "tab2",
               active = FALSE,
               DT::dataTableOutput(ns("daysummaryTable"))
             )
  )
)

)


}


#######
# Consolidated Log Server Module
#######

consolidatedlogModule <- function(input,output,session,data){

  ns <- session$ns

 data$HasGap <- ifelse(data$GAPGrossRevenue > 0, 1, 0)
 data$HasESC <- ifelse(data$ESCGrossRevenue > 0, 1, 0)  

 consolidatedLogVariables <- c("AcctID", "FSR", "DocSentDate",       "DocsToLenderDate",
                       "FundedDate", "HasGap", "HasESC", "LoanRevenue")

 logSummary <- data %>%
group_by(FundedMonthGroup) %>%
summarise(TotalCount = n()
          , TotalAmount = sum(LoanRevenue)
          , TotalGAP = sum(HasGap)
          , TotalESC = sum(HasESC))

  daySummary <- data %>%
group_by(FundedDayGroup) %>%
summarise(TotalCount = n()
          ,TotalAmount = sum(LoanRevenue))







  ### Consolidated Log Table
  output$consolidatedlogTable = DT::renderDataTable({

   data[consolidatedLogVariables]

 }, extensions = "Responsive", rownames = FALSE,
 caption = "Current Consolidated Log",
 filter = "bottom"
 )

 output$daysummaryTable = DT::renderDataTable({
   daySummary

  }, extensions = "Responsive", rownames = FALSE,
 caption = "Current Consolidated Log",
 filter = "bottom"
 )

 ### Charts

 #Fundedbyday Chart
 output$fundedbydayChart = renderHighchart({

   highchart() %>%
  hc_add_theme(hc_theme_ffx()) %>%
  hc_title(text = "Loans Funded By Day") %>%
  hc_add_series(data = daySummary, mapping = hcaes(x=FundedDayGroup, y=TotalAmount), type = "column", name = "Daily Loan Revenue",
                tooltip = list(pointFormat = "Daily Revenue ${point.TotalAmount} across {point.TotalCount} deals")) %>%
  hc_tooltip(crosshairs = TRUE)

# highchart() %>%
#   hc_add_theme(hc_theme_ffx()) %>%
#   hc_title(text = "Loans Funded By Day") %>%
#   hc_add_series(daySummary$TotalAmount, type = "column", name = "Daily Loan Revenue",
#                 tooltip = list(pointFormat = "Daily Revenue ${point.TotalAmount} across {point.TotalCount} deals")) %>%
#   hc_tooltip()

#hchart(daySummary, "column", hcaes(daySummary$FundedDayGroup, daySummary$TotalAmount))

 })


}

The highChart function that is commented out works correctly in displaying the columns wanted. The Axis is incorrect and the tooltips is unformatted but the data displays.

Using the Non-commented highchart with the HCAES call and other items, the plot is displayed without any data.

Below is code to reproduce the test data set for the daySummary, the dataframe in question.

FundedDayGroup <- as.Date(c('2019-02-01', '2019-02-4', '2019-02-05'))
TotalCount <- c(1,13,18)
TotalAmount <- c(0, 13166, 15625)
daySummary <- data.frame(FundedDayGroup, TotalCount, TotalAmount)
Jabberwockey
  • 349
  • 1
  • 6
  • 18
  • When I try to run your code, it is compiled without any errors but nothing is shown. How can I run (display) your chart? What I am missing? – raf18seb Mar 20 '19 at 14:18

1 Answers1

0

The issue ended up being Highcharter not interpreting the POSIXct format of the dates and needing to cast the date variable using as.Date. Additionally added some logic to handle the xAxis and setting the datetime. Code below

highchart() %>%
  hc_add_theme(hc_theme_ffx()) %>%
  hc_title(text = "Loans Funded By Day") %>%
  hc_add_series(data = daySummary, mapping = hcaes(x=as.Date(FundedDayGroup), y=TotalAmount), type = "column", name = "Daily Loan Revenue",
                tooltip = list(pointFormat = "Daily Revenue ${point.TotalAmount} across {point.TotalCount} deals")) %>%
  hc_xAxis(type = "datetime", labels=list(rotation = -45, y = 40) ) %>%
  hc_yAxis(title=list(text = "Revenue")) %>%
  hc_tooltip(crosshairs = TRUE)
Jabberwockey
  • 349
  • 1
  • 6
  • 18