ホームページ  >  に質問  >  本文

R 関数によって生成された HTML の埋め込み

HTMLを動的に構築してそのHTMLをレンダリングしたい クォートで。 実際のアプリケーションには iFrame の挿入が含まれます。 ただし、簡単にするために、<img> タグを作成するだけにしておきます。

これは私の .qmd コードです:

リーリー

レンダリングされ、関数が呼び出されるのは明らかです。 ただし、画像の代わりに HTML コードが表示されます:

これは簡単なことだとはわかっていますが、見つかりません。どうもありがとうございます!

P粉513316221P粉513316221181日前385

全員に返信(1)返信します

  • P粉883973481

    P粉8839734812024-04-02 11:25:43

    注意すべき点が 2 つあります:

    • まず、Quarto はデフォルトでコード ブロック出力を

       tag. To get the output asis you need to use the chunk option results: asis.

    • Secondly, sprintf (or even print) returns output enclosed within quotes. So after using results: asis, you would get the html tags but would also get the quotes. So you need to wrap the sprintf with cat to get intended results.

    ---
    format: html
    ---
    
    ```{r}
    #| echo: false
    imageLink <- function(iUrl, iText) {
      cat(sprintf(" %s", iUrl, iText))
    }
    ```
    
    ```{r}
    #| echo: false
    #| results: asis
    imageLink("https://www.united.com/8cd8323f017505df6908afc0b72b4925.svg", "united logo")
    ```
    
    and now, here's what it's supposed to look like:
    
     united logo
    でラップします。

    返事
    0
  • キャンセル返事