作者:Yihui Xie
译者:郑宝童
日期:2021.06.21


6.1 RStudio连接

In theory, you can render the book by yourself and publish the output anywhere you want. For example, you can host the HTML files on your own web server. We have provided a function publish_book() in bookdown to make it very simple to upload your book to https://bookdown.org, which is a website provided by RStudio to host your books for free. This website is built on top of “RStudio Connect”, an RStudio product that allows you to deploy a variety of R-related applications to a server, including R Markdown documents, Shiny applications, R plots, and so on.

理论上,您可以自己渲染这本书并在您想要的任何地方发布输出。例如,您可以在自己的 Web 服务器上托管 HTML 文件。我们在 bookdown 中提供了一个函数 publish_book() ,以便将您的书上传到 https://bookdown.org,这是一个由 RStudio 提供的免费托管您的书籍的网站。本网站建立在“RStudio Connect”之上,这是一款 RStudio 产品,可让您将各种 R 相关应用程序部署到服务器,包括 R Markdown 文档、Shiny 应用程序、R 绘图等。

You do not have to know much about RStudio Connect to publish your book to bookdown.org. Basically you sign up at https://bookdown.org/connect/, and the first time you try to run bookdown::publish_book(), you will be asked to authorize bookdown to publish to your bookdown.org account. In the future, you simply call publish_book() again and bookdown will no longer ask for anything.

您无需了解 RStudio Connect 即可将您的书发布到 bookdown.org。基本上,您在 https://bookdown.org/connect/ 上注册,并且第一次尝试运行 bookdown::publish_book() 时,系统会要求您授权 bookdown 发布到您的 bookdown.org 帐户。将来,您只需再次调用 publish_book() ,并且 bookdown 将不再要求任何内容。

  1. publish_book(name = NULL, account = NULL, server = NULL,
  2. render = c("none", "local", "server"))

The only argument of publish_book() that you may want to touch is render. It determines whether you want to render the book before publishing. If you have run render_book() before, you do not need to change this argument, otherwise you may set it to 'local':

您可能想要了解的 publish_book() 的唯一参数是 render。它确定您是否要在publish前渲染图书。如果您之前运行过 render_book() ,则无需更改此参数,否则您可以将其设置为 'local'

  1. bookdown::publish_book(render = "local")

If you have set up your own RStudio Connect server, you can certainly publish the book to that server instead of bookdown.org.

如果您已经设置了自己的 RStudio Connect 服务器,您当然可以将图书发布到该服务器而不是 bookdown.org。