我希望能够在遇到条件时显示一些内容,我真的很感激一些帮助。我觉得我很讨厌,但需要提升。我希望能够显示:
这是我的代码:
library(shiny)
ui = navbarPage(
"TEST",
tabPanel("Iris data",
uiOutput("tabs"),
conditionalPanel(condition = "input.level==1",
helpText("content1")
),
conditionalPanel(condition = "input.level==5",
helpText("content2")
)
)
)
server = function(input, output, session) {
output$tabs = renderUI({
Tabs <- as.list(colnames(iris))
Tabs_type <- lapply(iris, function(x) class(x))
for (i in 0:length(Tabs)){
Tabs[i] = lapply(paste(Tabs[i], sep=" "),tabPanel, value = Tabs_type[[i]])
}
do.call(tabsetPanel, c(Tabs, id = "value"))
})
}
shinyApp(ui, server)
我不知道如何将id更改为class(iris $ ...)
提前感谢您的帮助
答案 0 :(得分:0)
好的,你已经看过我在评论中指出的答案了。在这里,我已将它应用于您的问题。
library(shiny)
ui = navbarPage(
"TEST",
tabPanel("Iris data",
uiOutput("tabs"),
conditionalPanel(condition = "output.cond1",
helpText("content1")
),
conditionalPanel(condition = "output.cond2",
helpText("content2")
)
)
)
server = function(input, output, session) {
output$tabs = renderUI({
Tabs <- as.list(colnames(iris))
Tabs_type <- lapply(iris, function(x) class(x))
for (i in 0:length(Tabs)){
Tabs[i] = lapply(paste(Tabs[i], sep=" "),tabPanel, value = Tabs_type[[i]])
}
do.call(tabsetPanel, c(Tabs, id = "value"))
})
output$cond1 = reactive({
input$value == "numeric"
})
outputOptions(output, "cond1", suspendWhenHidden = FALSE)
output$cond2 = reactive({
input$value == "factor"
})
outputOptions(output, "cond2", suspendWhenHidden = FALSE)
}
shinyApp(ui, server)