---
title: "Publishing"
format: 
  html:
    toc: true
vignette: >
  %\VignetteIndexEntry{Publishing}
  %\VignetteEngine{quarto::html}
  %\VignetteEncoding{UTF-8}
---

## Overview

The **quarto** package includes several functions that enable you to publish static and interactive documents, websites, and books to [Posit Connect](https://posit.co/products/enterprise/connect/) and [shinyapps.io](https://www.shinyapps.io/). When publishing to Posit Connect, both simple content publishing (local rendering) as well as code publishing (rendering on Connect) are supported.

## Accounts

Before publishing to Posit Connect or shinyapps.io you should ensure that you have an account configured for publishing. 

For Posit Connect, use the `rsconnect::connectUser()` function for the server you are publishing to. For example:

```r
rsconnect::connectUser(server = "rsc.example.com")
```

You'll be prompted to authoring your account in a web browser.

For shinyapps.io, use the `rsconnect::setAccountInfo()` function. For example:

```r
rsconnect::setAccountInfo(name = 'norahjones', token = 'AB6783FD23', secret = '36x+k0bBy6W')
```

Note that you can copy and paste this code from the [Tokens](https://www.shinyapps.io/admin/#/tokens) page of your shinyapps.io admin panel.


## Documents

Use the `quarto_publish_doc()` function to publish a single document to Posit Connect. Note that the very _first time_ that you publish you should specify both the `server` and `account` that you want to use for publishing. For example:

```r
library(quarto)
quarto_publish_doc("document.qmd", server = "rsc.example.com", account = "njones")
```

Subsequent updates to the same document don't need to specify the `server` and `account`:

```r
quarto_publish_doc("document.qmd")
```

The example above renders content locally and publishes just the content to the server. You can also render on the server (uploading the source code required to render). You might want to do this in order to create scheduled versions of a report that update automatically when the underlying data changes. To do this, add the `render = "server"` argument: 

```r
quarto_publish_doc("document.qmd", 
                   server = "rsc.example.com", account = "njones",
                   render = "server")
```

## Websites

Use the `quarto_publish_site()` function to publish a [website](https://quarto.org/docs/websites/) or [book](https://quarto.org/docs/books/) to Posit Connect. Note that the very _first time_ that you publish you should specify both the `server` and `account` that you want to use for publishing. For example:

```r
library(quarto)
quarto_publish_site(server = "rsc.example.com", account = "njones")
```

Subsequent updates to the same site don't need to specify the `server` and `account`:

```r
quarto_publish_site()
```

The example above renders content locally and publishes just the content to the server. You can also render on the server (uploading the source code required to render). You might want to do this in order to create scheduled versions of a website that update automatically when the underlying data changes. To do this, add the `render = "server"` argument: 

```r
quarto_publish_site(server = "rsc.example.com", account = "njones",
                    render = "server")
```

## Interactive Docs

You can publish Shiny [interactive documents](https://quarto.org/docs/interactive/shiny/) to either Posit Connect or shinyapps.io. 

To publish to Posit Connect, specify both the `server` and `account` that you want to use for publishing (this is required for the first publish only). For example:

```r
library(quarto)
quarto_publish_app("shiny.qmd", server = "rsc.example.com", account = "njones")
```

To publish to shinyapps.io, use `server = "shinyapps.io"`:

```r
quarto_publish_app("shiny.qmd", server = "shinyapps.io")
```

For both services, subsequent publishes need not provide the `server` or `account`:

```r
quarto_publish_app("shiny.qmd")
```


