mark
mark

Reputation: 47

Trouble including a HTML file which contains a tippy elememt in a shiny app

I am trying to use tippy to provide hover text on certain words within passages of text that will appear in a shiny app. To make it easier to edit long passages of instructonal text, rather than include the text directly in the shiny UI I have generated the instructions in separate RMarkdown files and then embedded the corresponding HTML files using shiny::includeHTML().

The tippy hover texts work nicely in the rendered HTML but does not appear in the shiny app.

Calling tippy directly in the app does work, so that is an option, but if possible I would prefer to keep the long instructional text separate to the app file.

The .Rmd file (which produces the HTML) and the app.R file below illustrates the problem. Thank you for any suggestions.

long_text.Rmd

---
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
library(tippy)
library(shiny)
```

Regular HTML tags work:

```{r}
tags$p('Hello', tags$span(style="color:blue", 'world'))
```


But tippy does not:

```{r}
tippy('This works in the HTML file but not when embedded in the Shiny app', 'Uh oh')
```

app.R

library(shiny)
library(tippy)

ui <- fluidPage(

tags$p(tippy('Using tippy directly in the Shiny UI works fine', 'nice')),

htmlOutput('text')    
)

server <- function(input, output) {

output$text <- renderUI(includeHTML('longText.html'))
    
}

shinyApp(ui = ui, server = server)

Upvotes: 0

Views: 206

Answers (1)

guasi
guasi

Reputation: 1769

Build the HTML document as a fragment. The tool tips will not work on the knitted HTML fragment, but when you include the built HTML file it in the Shiny app, you'll see the tool tips.

 ---
 output: html_fragment
 ---

Upvotes: 1

Related Questions