我正在尝试创建如下所示的内容:
示例代码:
图书馆(闪亮) 图书馆(闪亮仪表板)
data <- data_frame(
category = c(rep("Superhero outfits", 5), "Game of Thrones houses", rep("My favourite bars", 2), "I am groot"),
keywords = c("superman + red + cape", "Batman + black + cape", "Hulk + green + purple", "Spiderman + web", "Groot + wood + plant", "wolf + stark",
"chocolate + nuts", "protein + cookie", "I + groot"),
author = c(rep("Preter Parker", 3), rep("Bruce Wayne", 5), "Groot"),
date = c(rep(Sys.Date()))
)
shinyApp(
ui = dashboardPage(
dashboardHeader(title = "MyApp"),
dashboardSidebar(),
dashboardBody(
column(
selectizeInput("selectCategory", NULL, choices = unique(data$category)),
uiOutput("displayChoicesUI"),
width = 4
)
)
),
server = function(input, output) {
choices_list <- reactive({
if(!is.null(input$selectCategory)){
data %>%
filter(category == input$selectCategory) %>%
mutate(ID = row_number())
}
})
output$displayChoicesUI <- renderUI({
if(!is.null(input$selectCategory)){
lapply(1:nrow(choices_list), function(i){
column(
width = 12,
column(
width = 8,
verbatimTextOutput(paste0("text_", choices_list$ID[i]))
),
column(
width = 2,
actionLink(paste0("delete_", choices_list$ID[i]), HTML("<i class='fa fa-times-circle'></i>"))
),
column(
width = 2,
actionLink(paste0("edit_", choices_list$ID[i]), HTML("<i class='fa fa-edit'></i>"))
)
)
})
}
})
lapply(1:????, function(i){
output[[paste0("text_", i)]] <- renderText({
HTML(paste0(choices_list()$keywods[i], br(), choices_list()$author, ", ", choices_list()$date))
})
})
lapply(1:????, function(i){
observeEvent(input[[paste0("delete_", i)]], {
})
})
lapply(1:????, function(i){
observeEvent(input[[paste0("edit_", i)]], {
})
})
}
)
问题是,由于我不知道该类别中会有多少关键字,我如何循环遍历它以创建反应性 - 输出关键字和作者并使按钮起作用。
迭代次数是一个反应值,但是我不能在 lapply 中添加一个反应值。做某事lapply(1:nrow(choices_list()), function(i){})
给我Evaluation error: Operation not allowed without an active reactive context. (You tried to do something that can only be done from inside a reactive expression or observer.).
有什么办法可以做我想要做的,或者有更好的方法吗?我没主意了。