IncludeMarkdown的闪亮反应?

时间:2015-12-30 16:08:54

标签: html r shiny

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

我希望在*.Md条件中包含一个反应性降价文件(mainPanel),条件是selectInput的输入。我该怎么做?

我在renderTextrenderPrinteval内使用includeMarkdown尝试过各种变体。到目前为止似乎没有任何工作。

EG。

### 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')
  

聆听http://127.0.0.1:6421聆听   readLines(con)中的警告:
   无法打开文件'md_file':没有这样的文件或目录
  readLines(con)出错:无法打开连接

1 个答案:

答案 0 :(得分:3)

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

在您的用户界面中:

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)
})

谢谢,乔!