JasonAizkalns
JasonAizkalns

Reputation: 20483

Is it possible to set host and port in Rmarkdown document with runtime: shiny?

Say we are working with an rmarkdown document with the following yaml (example runtime: shiny "app"):

---
runtime: shiny
output: html_document
---

### Here are two Shiny widgets
```{r echo = FALSE}
selectInput("n_breaks", label = "Number of bins:",
              choices = c(10, 20, 35, 50), selected = 20)

sliderInput("bw_adjust", label = "Bandwidth adjustment:",
              min = 0.2, max = 2, value = 1, step = 0.2)
```

### ...that build a histogram.

```{r echo = FALSE}
renderPlot({
  hist(faithful$eruptions, probability = TRUE,
       breaks = as.numeric(input$n_breaks),
       xlab = "Duration (minutes)",
       main = "Geyser eruption duration")

  dens <- density(faithful$eruptions, adjust = input$bw_adjust)
  lines(dens, col = "blue")
})
```

With a regular shiny app we can set the host and port by setting options: shinyApp(ui, server, options = list(host = '123.45.67.89', port = 1234))

Is it possible to establish and set a specific host and port in the YAML? Or somewhere else in the setup?

Upvotes: 1

Views: 508

Answers (1)

lz100
lz100

Reputation: 7360

do this

option1

rmarkdown::run("test.Rmd", shiny_args = list(host = '123.45.67.89', port = 1234))

test.Rmd is the name of your doc. make sure your host 123.45.67.89 is valid. Usually is 127.0.0.1 for local testing or don't provide it to use the default.

option 2

options(shiny.port = 1234)
options(shiny.host = '127.0.0.1')
rmarkdown::run("test.Rmd")

Upvotes: 2

Related Questions