我想根據用戶輸入顯示不同的 html 檔案。基本上,用戶在兩個pickerinput元素中進行選擇,并根據選擇顯示不同的 html 檔案。
我的用戶界面中有。電阻
fluidRow( style = "background-color:#FFFAFA00;",
htmlOutput("example")
))),
并在我的服務器中。電阻
示例 <- 反應式({
if (input$chap == "ai" & input$cat == "ch") {
htmlOutput("aich")
}
else if (input$chap == "ai" & input$cat == "pr") {
htmlOutput("aipr")
}
})
選擇后沒有任何反應。關于這個的任何想法
uj5u.com熱心網友回復:
我們可以試試這個:
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://www.uj5u.com/net/372999.html
下一篇:在R中的資料幀串列上運行PCA
