麻烦,包括一个html文件,该文件包含闪亮的应用中包含tippy lememt

发布于 2025-02-13 12:26:05 字数 1099 浏览 0 评论 0原文

我正在尝试使用Tippy在文本中会出现在闪亮应用中的文本中的某些单词上提供悬停文本。为了更易于编辑教学文本的长段落,而不是直接将文本包含在Shiny UI中,我已经在单独的rmarkDown文件中生成了指令,然后使用shiny :: includehtml()。

Tippy Hover文本在渲染的HTML中很好地工作,但没有出现在Shiny应用中。

直接在应用程序中调用Tippy确实有效,因此这是一个选择,但是如果可能的话,我希望将长的教学文本与应用程序文件分开。

.RMD文件(生产HTML)和下面的App.r文件说明了问题。谢谢您的建议。

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)

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你怎么这么可爱啊 2025-02-20 12:26:05

将HTML文档构建为片段。该工具提示将无法在针织的HTML片段上使用,但是当您在Shiny应用中包含构建的HTML文件时,您会看到工具提示。

 ---
 output: html_fragment
 ---

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
 ---
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文