试图将这些想法更进一步:
我想包括反应降价文件(*.Md
)在mainPanel
有条件的输入到selectInput
。我该怎么做?
我已经尝试了renderText
,renderPrint
并使用eval
inside 的变体includeMarkdown
。到目前为止似乎没有任何效果。
例如。
### 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')
Run Code Online (Sandbox Code Playgroud)
侦听http://127.0.0.1:6421
readLines(con) 中的警告:
无法打开文件“md_file”:没有这样的文件或目录
readLines(con) 中的错误:无法打开连接
根据在 Shiny Google 小组中与 Joe Cheng 的讨论,答案是:
在您的用户界面中:
uiOutput("md_file")
Run Code Online (Sandbox Code Playgroud)
在您的服务器中:
output$md_file <- renderUI({
file <- switch(input$var1,
option1 = "option1.Md",
option2 = "option2.Md",
option2 = "option3.Md",
stop("Unknown option")
)
includeMarkdown(file)
})
Run Code Online (Sandbox Code Playgroud)
谢谢,乔!