我想根据用户输入显示不同的html文件。基本上,用户在两个选择器输入元素中进行选择,并在选择的基础上显示不同的html文件。
我在我的ui中。R
fluidRow( style = "background-color:#FFFAFA00;",
htmlOutput("example")
))),在我的服务器上。R
示例<-反应性({
if (input$chap == "ai" & input$cat == "ch") {
htmlOutput("aich")
}
else if (input$chap == "ai" & input$cat == "pr") {
htmlOutput("aipr")
}
})被选中时什么都不会发生。对此有何想法?
发布于 2021-12-04 20:33:14
我们可以试试这个:
observe({
if (input$chap == "ai" & input$cat == "ch") {
output$example <- renderText("html_code_here")
}
else if (input$chap == "ai" & input$cat == "pr") {
output$example <- renderText("html_code_here")
}
})而且,我认为observeEvent(c(input$chap, input$chap), {...})可以工作。
很难用所提供的信息来判断这是否有效,但我做了一个例子。
library(shiny)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(textInput(inputId = 'chap','input 1',placeholder = 'ai'),
textInput(inputId = 'cat', 'input 2',placeholder = 'ch')),
mainPanel(htmlOutput('example')))
)
server <- function(input, output, session) {
observe({
req(input$chap)
if (input$chap == "ai" & input$cat == "ch") {
output$example <- renderText("<h1>This is the H1</h1>")
}
else { if (input$chap == "ai" & input$cat == "pr") {
output$example <- renderText("aipr")
}
}
})
}
shinyApp(ui, server)

https://stackoverflow.com/questions/70229178
复制相似问题