私は、ユーザ入力に基づいてコンピュータコードを動的に生成し、それをユーザに提示してデータベースに送られるクエリを正確に見ることができるShinyアプリケーションを持っています。私はプリズムの構文が強調表示されているので、プリムが機能していることを知っています。サーバーで生成され、renderText
とhtmlOutput
を経由してユーザーに送信されたコードの場合、強調表示は機能しません。ここRのShiny appでhtmlOutputを使ってシンタックスハイライトを有効にする方法
単純な例の画像である:(光沢のあるアプリのwww
フォルダおよびprism.cssとprism.js)このRファイルを使用して作られた
ui <- shinyUI(fluidPage(
tags$head(
tags$link(rel = "stylesheet", type = "text/css", href = "prism.css")
),
tags$body(
tags$script(src="prism.js")
),
HTML("<pre><code class='language-sql'>SELECT * FROM mytable WHERE 1=2
-- this chunk should be syntax highlighted and it is
</code></pre>"),
HTML("<pre>SELECT * FROM mytable WHERE 1=2
-- this chunk should not be syntax highlighted
</code></pre>"),
htmlOutput("sql")
)
)
# Define the server code
server <- function(input, output) {
txt <- "<pre><code class='language-sql'>SELECT * FROM mytable WHERE 1=2
-- this chunk should be syntax highlighted but isn't for some reason,
-- presumably connected to it getting to the UI via renderText and htmlOutput
</code></pre>"
output$sql <- renderText(txt)
}
私は輝いている、第三(動作しない)チャンクによって生成されたWebページに
<div class="shiny-html-output shiny-bound-output">
内にあること、そして正しく
<pre>
と
<code class="language-sql">
TAに包まれて見ることができますDOMエクスプローラで
最初のチャンクのようなgs。したがって、そのdivで囲まれていることは、prism.jsが強調表示することをやめさせることです。
3番目のチャンクを最初のようにハイライト表示するにはどうすればよいですか?
ありがとう、これは完全に機能しました。 –