我希望有一个简单的问题,把一个标签顺序列表传递到一个闪亮的仪表板上。我想要做的是有一个函数,根据一个过滤的类别,生成一个排序的项目点列表。
下面是一个简单的示例,说明我希望能够使用名为nba_teams的数据框架做什么
teams conference
Bulls Eastern
Nuggets Western
Celtics Eastern
Lakers Western现在,如果我编写这个函数,它将列出相应会议的列表:
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))
}
}
我想要做的是在一个选项卡框中这样做:
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))
}
})),但这只会使方框成为空白,不会为每个观察结果填充一个子弹点。
有什么建议吗?谢谢!
发布于 2018-10-23 14:26:07
在这种情况下,我会使用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)https://stackoverflow.com/questions/52938451
复制相似问题