HighCharter HCAES方法在R Shiny Dashboard中不产生任何可视化

问题描述 投票:0回答:1

试图建立堆栈交换问题:R Highcharter: tooltip customization

有一个R模块(下面)。这会提取一些数据,并提供包括高图可视化的UI。

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))

 })


}

注释掉的highChart函数在显示所需列时可正常工作。轴不正确,工具提示未格式化但数据显示。

使用带有HCAES调用的非注释高图和其他项目,将显示没有任何数据的图表。

下面是重现有关数据框daySummary的测试数据集的代码。

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)
r highcharts
1个回答
0
投票

问题最终是Highcharter没有解释日期的POSIXct格式并且需要使用as.Date来转换日期变量。另外添加了一些逻辑来处理xAxis并设置日期时间。代码如下

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)
© www.soinside.com 2019 - 2024. All rights reserved.