【问题标题】:Shiny reactivity with IncludeMarkdown?IncludeMarkdown 的闪亮反应?
【发布时间】:2015-12-30 16:08:53
【问题描述】:

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

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

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

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) 中的错误:无法打开连接

【问题讨论】:

    标签: html r shiny


    【解决方案1】:

    根据在 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)
    })
    

    谢谢,乔!

    【讨论】:

      猜你喜欢
      • 2013-07-16
      • 2015-06-23
      • 2014-08-23
      • 2020-10-13
      • 2016-02-22
      • 2021-05-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多