[英]ShinyDashboard Dynamic Bullet Points
I have hopefully a simple problem to pass a tags ordered list to in a Shiny Dashboard.我希望有一个简单的问题可以将标签有序列表传递到闪亮的仪表板中。 What I'd like to do is have a function that makes an ordered list of bullet points based upon on a filtered category.
我想要做的是有一个函数,它根据过滤的类别制作一个有序的项目符号列表。
Here is a trivial example of what I'd like to be able to do with a data frame called nba_teams这是我希望能够使用名为 nba_teams 的数据框执行的操作的一个简单示例
teams conference
Bulls Eastern
Nuggets Western
Celtics Eastern
Lakers Western
Now if I write this function it will break out the list for the respective conferences:现在,如果我编写此函数,它将列出各个会议的列表:
for (row in 1:nrow(nba_teams)){
teams <- nba_teams[row, "teams"]
conference <- nba_teams[row,"conference"]
if(grepl("Western",conference)){
print(tags$li(teams))
}
}
What I'd like to do is to have this in a tab box such that:我想做的是将它放在一个选项卡框中,以便:
box(
title = "Western Conference",
tags$ol(
for (row in 1:nrow(nba_teams)){
teams <- nba_teams[row, "teams"]
conference <- nba_teams[row,"conference"]
if(grepl("Western",conference)){
print(tags$li(teams))
}
})),
But this just leaves the box blank and won't populate the box with a bullet point for each observation.但这只会使框为空白,并且不会为每个观察结果用项目符号点填充框。
Any suggestions?有什么建议? Thank you!
谢谢!
I would use lapply
in this case:在这种情况下,我会使用
lapply
:
library(shiny)
library(shinydashboard)
nba_teams <- data.frame(team = c("Bulls", "Nuggest", "Celtics", "Lakers"),
conference = c("Eastern", "Western", "Eastern", "Western"))
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
box(
title = "Western Conference",
tags$ol(
lapply(1:nrow(nba_teams), function(x) {
if (nba_teams$conference[x]=="Western") {
return(tags$li(nba_teams$team[x]))
}
})
)
)
)
)
server <- function(input, output, session) {}
shinyApp(ui, server)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.