Trying to take these ideas a step further:
I want to include a reactive markdown file ( *.Md
) in a mainPanel
conditional on the input to a selectInput
. How do I do it?
I've tried variations on renderText
, renderPrint
and using eval
inside includeMarkdown
. Nothing seems to work so far.
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')
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
Based on a discussion with Joe Cheng in the Shiny Google group, the answer is:
In your UI:
uiOutput("md_file")
In your server:
output$md_file <- renderUI({
file <- switch(input$var1,
option1 = "option1.Md",
option2 = "option2.Md",
option2 = "option3.Md",
stop("Unknown option")
)
includeMarkdown(file)
})
Thanks, Joe!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.