2016-02-26 82 views
1

我想在reveal.js演示文稿中构建一些Highchart(包HighCharter)。 现在我正在修改这个page的spiderweb图表。
这是我的代码:highcharter降价演示文稿

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


``` 

嗯,代码工作proprelly正常sintax,但后来我将其包含在RMarkdown sintax结果的错误:

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

别人的帮助?

+0

喜谐音的解决方案!为什么使用gg $ show()代替gg? Highcharter没有展示方法!编辑:我现在看到我无法在r演示文稿中显示图表。我会检查 – jbkunst

+0

Hi @jbkunst,其实我尝试了'gg',也没有创建任何objet ...但这些解决方案在演示文稿中不起作用。感谢您的帮助 – Giorjet

+0

Hi @jbkunst,您有机会看看您是否可以在演示文稿中放置Highchart?如果我们不能这样做会很耻辱,因为他们看起来很好。在此先感谢 – Giorjet

回答

1

Okey my friend!这项工作(在我的设计中)。

这里http://jkunst.com/highcharter/presentation/

首先的结果,你必须使用下一个函数,而不是打印的htmlwidget将它保存在一个HTML文件,然后把一个iframe 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/429这里https://github.com/ramnathv/slidify/issues/414

+0

我在搜索,似乎这是在htmlwidgets实施https://github.com/ramnathv/htmlwidgets/pull/154 – jbkunst

+0

嗨@jbkunst ....它的工作原理!非常感谢。顺便说一下...你认为可以把图表surce文件放在一个文件夹“surce”中吗?只是为了避免人们在查找演示文稿之前打开​​所有文件?还有另一个问题:非常美丽的美国地图!你认为是否可以对意大利地区和其他欧洲国家的省份和地区做同样的事情? – Giorjet

+0

嗨@Giorjet,它的可能,1)只需在该位置写html,然后修改iframe字符串以在正确的位置查找2)明显地,它可能只需要编写类似此代码的http:// jkunst。 com/highcharter/highmaps.html使用https://raw.githubusercontent.com/johan/world.geo.json/master/countries/ITA.geo.json – jbkunst