2016-02-26 93 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