尝试将这些想法更进一步:
我想在 mainPanel
中包含一个响应式 Markdown 文件 (*.Md
),以 selectInput
的输入为条件。我该怎么做?
我尝试了 renderText
、renderPrint
的变体,并在 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/