R:动态创建的bucket_列表的自定义样式
我创建了一个函数,可以根据先前的输入动态创建多个存储桶列表,而无需手动创建每个R:动态创建的bucket_列表的自定义样式,r,shiny,R,Shiny,我创建了一个函数,可以根据先前的输入动态创建多个存储桶列表,而无需手动创建每个add\u rank\u list 然而,我还不能像创建非动态的桶列表那样对其进行风格化 下面的示例演示了这一点 它使用HTML标记设置样式class=c(“默认排序”、“自定义排序”)然后作为选项包含在bucket\u列表中。但是,我不能在动态创建的bucket_列表的代码中无误地放置此代码 library(shiny) library(sortable) ui <- fluidPage( tags$st
add\u rank\u list
然而,我还不能像创建非动态的桶列表那样对其进行风格化
下面的示例演示了这一点
它使用HTML标记设置样式class=c(“默认排序”、“自定义排序”)
然后作为选项包含在bucket\u列表中。但是,我不能在动态创建的bucket_列表的代码中无误地放置此代码
library(shiny)
library(sortable)
ui <- fluidPage(
tags$style(
HTML("
.rank-list-container.custom-sortable {
border-color:#FFFFFF;
}
.custom-sortable .rank-list-item {
border-color:#FFFFFF;
}
")),
uiOutput("bucket_1_and_2"),
fluidRow( column(6,uiOutput("bucket_1")),column(6,
uiOutput("bucket_2")))
)
server <- function(input, output, session) {
bucket_1 <- reactive({lapply(c("Default","Styling"), function(x) {
add_rank_list(
text = "",
input_id = paste0("bucket_1_",x),
labels = x
)
})
})
output$bucket_1_and_2 <- renderUI({
do.call("bucket_list", args = c(
header = "",
group_name = "bucket_sort",
orientation = "horizontal",
# The following code does not function:
# class = c("default-sortable", "custom-sortable"),
bucket_1()
))
})
output$bucket_1 <- renderUI({
bucket_list(
header = "",
group_name = "bucket_sort",
orientation = "horizontal",
class = c("default-sortable", "custom-sortable"),
add_rank_list(
text = "",
input_id = "bucket_1",
labels = "Custom"
))
}
)
output$bucket_2 <- renderUI({
bucket_list(
header = "",
group_name = "bucket_sort",
orientation = "horizontal",
class = c("default-sortable", "custom-sortable"),
add_rank_list(
text = "",
input_id = "bucket_2",
labels = "Styling"
))
}
)
}
shinyApp(ui, server)
库(闪亮)
图书馆(可分类)
ui我从来没有使用过bucked_list
,所以我不确定,但也许你想要:
output$bucket_1_and_2 <- renderUI({
bucketLists <- lapply(bucket_1(), function(x){
bucket_list(
header = "",
group_name = "bucket_sort",
orientation = "horizontal",
class = c("default-sortable", "custom-sortable"),
x
)
})
do.call(tagList, buckedLists)
})
输出$bucket\u 1\u和\u 2为什么使用do.call
?如果确实需要,请尝试将列表设置为args
参数:args=list(…)
。此外,我从未使用过bucket\u list
,但通常会将HTML元素的class
属性设置为单个字符串,并用空格分隔类:class=“default sortable custom sortable”
。谢谢。我已根据您的意见更改了代码。但是,错误仍然存在:警告:is_add_rank_list(x=dot)中的错误不正确
惊人,@Stéphane Laurent。非常感谢。