html - 与 IncludeMarkdown 的 Shiny react ?

标签 html r shiny

尝试将这些想法更进一步:

我想在 mainPanel 中包含一个响应式 Markdown 文件 (*.Md),以 selectInput 的输入为条件。我该怎么做?

我尝试了 renderTextrenderPrint 的变体,并在 includeMarkdown 中使用了 eval。到目前为止似乎没有任何效果。

例如。

### ui.R

shinyUI(fluidPage(    
  sidebarLayout(
    sidebarPanel(
      selectInput("var1",
                  label= "Please Select option",
                  choices= c("option1", "option2", "option3"),
                  selected= "option1"
    ),

    mainPanel(
      h3("guide:")
      includeMarkdown("md_file")
    )
  )
))

### server.R
shinyServer(function(input, output) {

   output$md_file <- 
     if (input$var1 == "option1") {
       renderPrint({"option1.Md"})
     } else if (input$var1 == "option2") {
       renderPrint({"option2.Md"})
     } (input$var1 == "option3") {
       renderPrint({"option3.Md"})
     }
   })
})


R> shiny::runApp('C:/Shiny_demo')

Listening on http://127.0.0.1:6421
Warning in readLines(con) :
cannot open file 'md_file': No such file or directory
Error in readLines(con) : cannot open the connection

最佳答案

根据与 Joe Cheng 在 Shiny Google 组的讨论,答案是:

在您的用户界面中:

uiOutput("md_file")

在您的服务器中:

output$md_file <- renderUI({
  file <- switch(input$var1,
    option1 = "option1.Md",
    option2 = "option2.Md",
    option2 = "option3.Md",
    stop("Unknown option")
  )
  includeMarkdown(file)
})

谢谢,乔!

关于html - 与 IncludeMarkdown 的 Shiny react ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34532988/

相关文章:

javascript - 在 React Modal 中插入 ID

html - 如何使用 Angular 将元素保存在数据库容器中?

返回 NaN 而不是 -1

r - 是否可以将 ggplot 与 R 中的单位包一起使用?

r - Select/Deselect All 按钮用于 Shiny 的变量选择

r - 如何使展示模式在 rmarkdown/knitr 交互式 Shiny 文档中工作?

html - 将文本与样式元素内的左下角对齐

html - 如何调整标签之间垂直虚线的长度?

r - 条件连接数据帧 R

r - 观察事件以隐藏 Shiny 的操作按钮