Skip to content

renderUI can't find local images when using flexdashboard #439

@melissagwolf

Description

@melissagwolf

I have a shiny app that begins with a series of instructions that are conditional on the input that a user selects. I want to include both text and a local image as part of the instructions. renderUI seems to be unable to locate the local image. include_graphics displays the image as expected, but I can not make it conditional on the input that the user selects.

---
title: "MyApp"
runtime: shiny
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
---

```{r setup, include=FALSE}
library(flexdashboard)
```

Sidebar {.sidebar}
=====================================

```{r}
selectInput("input_type", 
            label = "Select an input",
            choices = list(" "=1,
                           "Input 1" = 2,
                           "Input 2" = 3))
```


MyApp
=====================================

Row {.tabset}
-----------------------------------------------------------------------

### img src

```{r}
renderUI({
  
  input_type <- input$input_type
  
  if (input_type == 1) {
    HTML('Welcome to my app! Here are some instructions about how to use it. 
A helpful image will appear when you select an input.')} 
  
  else if (input_type == 2) {
    HTML('Here are some instructions.
         <div><img src = "Posit_1.png"></div>')
  } 
  
  else if (input_type == 3) {
    HTML('Here are some other instructions. 
         <div><img src = "RStudio_2.png"></div>')
  }
  
})
```

### include_graphics

```{r}
knitr::include_graphics("Posit_1.png")
knitr::include_graphics("Rstudio_2.png")
```
image image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions