Had the same problem. When I executed slidify(index.Rmd)
, there was a message saying PhantomJS not found
, and suggesting me run webshot::install_phantomjs()
. So I did and the error was gone. However I still got no plotly interactive map output. It was blank.
Also tried the following code in terminal, which worked for some people but not for me. I got html file output, and there still wasn't a map. It comes from this post. It might work for you.
Rscript -e "library(knitr); library(rmarkdown);
rmarkdown::render('index.Rmd', output_file='index.html')"
I am sure it is plotly. Cause ggplots works fine.
Update:
Reinstalled/updated the wetshot package by running install.packages("webshot")
, then ran webshot::install_phantomjs()
again, then library(knitr); library(rmarkdown); rmarkdown::render('index.Rmd', output_file='index.html')
. It worked. The html file has a plotly map, though it doesn't appear in the Knitr preview window.
Update:
By adding the following code, I am able to display the map in the sides. Refer to this post.
htmlwidgets::saveWidget(as_widget(p), "p.html")
cat('<iframe src="./p.html" width=100% height=100% allowtransparency="true"> </iframe>')
Full context would be something listed below.
library(plotly)
cities <- readRDS("D:/R/data/cn_cities.rds")
cities <- cities[1:50,]
geo <- list(
scope = 'asia',
projection = list(type = 'Mercator'),
showland = TRUE,
landcolor = toRGB("gray85"),
countrycolor = toRGB("white"),
subunitcolor = toRGB("white"),
countrywidth = 1,
subunitwidth = 1)
p <- plot_geo(cities,
locationmode='CHN',
sizes=c(1, 200)) %>%
add_markers(x=~lng, y=~lat,
size=~sqrt(population),
hoverinfo="text",
text=~paste(city, "<br />", population)) %>%
layout(title='',
geo=geo)
htmlwidgets::saveWidget(as_widget(p), "p.html")
cat('<iframe src="./p.html" width=100% height=100% allowtransparency="true"> </iframe>')