Markdown打破了Shiny中的fluidPage列宽

时间:2017-04-04 09:52:51

标签: r shiny

按照标题。举例说明:

md = "# Lorem ipsum

1. dolor sit amet, amet ut integer vitae, justo pretium sed praesent, velit vitae proin molestie metus nec. A mi id quisque libero, in sed urna non etiam iaculis id, purus cum sit et. Maecenas purus sit rhoncus fringilla velit, etiam et justo risus pharetra, leo convallis ut platea, turpis tellus urna sed, leo scelerisque velit nam urna. Felis tincidunt fringilla, suspendisse molestie dui, phasellus aliquam nec adipiscing enim fusce metus, vulputate dictumst etiam est a. Rhoncus ut, netus aenean rutrum vehicula ipsum, maecenas nec ut mauris."

shinyApp(
  fluidPage(
    fluidRow(
      column(3,
             selectInput('countries', 'countries', state.name, "country")
      ),
      column(9,
             plotOutput('plot'),
             uiOutput('markdown')
      )
    )
  ),

  function(input, output, session) {
    output$plot <- renderPlot({
      plot(rnorm(100))
    })
    output$markdown <- renderUI({
      HTML(markdown::markdownToHTML(text = md))
    })
  },
  options = list(launch.browser=T)
)

产生:

enter image description here

将其与渲染文本进行比较:

shinyApp(
  fluidPage(
    fluidRow(
      column(3,
             selectInput('countries', 'countries', state.name, "country")
      ),
      column(9,
             plotOutput('plot'),
             textOutput('txt')
      )
    )
  ),

  function(input, output, session) {
    output$plot <- renderPlot({
      plot(rnorm(100))
    })
    output$txt <- renderText(md)
  },
  options = list(launch.browser=T)
)

这应该是它的样子:

enter image description here

这是一个错误吗?

1 个答案:

答案 0 :(得分:3)

fragment.only = TRUE的调用中需要markdownToHTML()选项:

 output$markdown <- renderUI({
      HTML(markdown::markdownToHTML(text = md,
                                    fragment.only = TRUE))
    })

添加此内容后,该应用程序看起来与您的第二个示例完全相同:

enter image description here