highcharter降价演示文稿

时间:2016-02-26 00:26:19

标签: r highcharts r-markdown reveal.js

我试图在reveal.js演示文稿中构建一些Highchart(包HighCharter)。 现在我正在调整这个page的蜘蛛网图表 这是我的代码:

 ```{r, echo=FALSE, message=FALSE, results = 'asis', comment = NA}
library("highcharter")
library(magrittr)

gg<- highchart() %>% 
  hc_chart(polar = TRUE, type = "line") %>% 
  hc_title(text = "Where do you usually buy solar protection products? (%)") %>% 
  hc_subtitle(text = "Move the mouse pointer on the spiderweb chart to view the data") %>% 
  hc_xAxis(categories = c('Supermarket',
                      'Department Store',
                      'Pharmacy',
                      'Perfumery',
                      'Herbalist',
                      'Internet',
                      'Shop for Personal Care'
  ),
  tickmarkPlacement = 'on',
  lineWidth = 0) %>% 
hc_yAxis(gridLineInterpolation = 'polygon',
       lineWidth = 0,
       min = 0) %>% 
  hc_series(
    list(
      name = "Male (%)",
      data = c(14.3,
           9.1,
           35.8,
           26.3,
           4.9,
           4.6,
           4.1
  ),
  pointPlacement = 'on', color="#88C425"
  ),
 list(
  name = "Female (%)",
  data = c(17.0,
           7.0,
           40.2,
           28.8,
           18.3,
           2.2,
           3.6
  ),
  pointPlacement = 'on', color="#A8DBA8"
  )
  )


gg$show("inline", include_assets = TRUE)


```

嗯,代码在正常的sintax中正常运行,但后来我将它包含在RMarkdown sintax中,结果是错误:

Error in eval(expr, envir, enclos) : 
tentativo di applicare una non-funzione
Calls: <Anonymous> ... handle -> withCallingHandlers -> withVisible -> eval -> eval

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:1)

我的朋友,好吧!这项工作(在我的身上)。

结果http://jkunst.com/highcharter/presentation/

首先,您必须使用下一个函数,而不是打印htmlwidget将其保存在html文件中,然后将iframe html标记调用此html。

knit_print.htmlwidget <- function(x, ..., options = NULL){

  options(pandoc.stack.size = "2048m")

  wdgtclass <- setdiff(class(x), "htmlwidget")[1]
  wdgtrndnm <- paste0(sample(letters, size = 7), collapse = "")
  wdgtfname <- sprintf("wdgt_%s_%s.html", wdgtclass, wdgtrndnm)

  htmlwidgets::saveWidget(x, file = wdgtfname, selfcontained = TRUE, background = "transparent")

  iframetxt <- sprintf("<iframe  frameBorder=\"0\" src=\"%s\" width=\"100%%\"   height=\"600\"></iframe>", wdgtfname)

  knitr::asis_output(iframetxt)
}

基本上实现这里提到的部分解决方案https://github.com/ramnathv/slidify/issues/429https://github.com/ramnathv/slidify/issues/414