r - 使用 updatePrettyCheckboxGroup 时不应用 prettyCheckboxGroup 的格式选项
问题描述
我正在编写一个闪亮的应用程序,其中prettyCheckboxGroup
选项由用户上传的 .csv 文件填充。如果我手动设置choices
(例如“A”、“B”、“C”),那么我可以更改status
、shape
、outline
等。但是,如果我在服务器代码中使用updatePrettyCheckboxGroup
基于 an observeEvent
,那么结果就是默认样式.
ui <- navbarPage("Tabbed page",
tabPanel("Works",
prettyCheckboxGroup(
inputId = "Id001",
label = "Checkboxes with status",
choices = c("A", "B", "C"),
inline = TRUE,
status = "danger",
shape = "round"),
),
tabPanel("Doesn't Work",
fileInput("Line_Dataset", label = "Choose Data"),
prettyCheckboxGroup(
inputId = "Broken",
label = "Checkboxes with status",
choices = NULL,
inline = TRUE,
status = "danger",
shape = "round"),
)
)
server <- function(input, output, session) {
LineFile <- eventReactive(c(input$Line_Dataset), {
read_csv(input$Line_Dataset$datapath, col_names = T)
})
observeEvent(input$Line_Dataset,
{elements_line_data <- LineFile() %>%
colnames()
updatePrettyCheckboxGroup(session,
"Broken",
choices = elements_line_data)
})
}
shinyApp(ui,server)
使用 updatePrettyCheckboxGroup 时应该将status
和参数放在哪里?shape
他们需要进入服务器文件吗?
请注意,我在尝试使用时得到了相同的结果awesomeCheckboxGroup
,update...
但由于格式化选项的数量,我选择使用 pretty。
谢谢,杰里米
PS 我很抱歉没有提供 .csv 但任何文件都可以使用
解决方案
该函数updatePrettyCheckbox()
无法传递参数状态和形状,因此生成正确复选框的唯一选项是直接使用renderUI()
. 无论如何,问题是因为这两个参数在updatePrettyCheckbox()
被调用时不存在,所以重新呈现了默认格式。
library(shiny)
library(shinyWidgets)
library(tidyverse)
ui <- navbarPage("Tabbed page",
tabPanel("Works",
prettyCheckboxGroup(
inputId = "Id001",
label = "Checkboxes with status",
choices = c("A", "B", "C"),
inline = TRUE,
status = "danger",
shape = "round")
),
tabPanel("Doesn't Work",
fileInput("Line_Dataset", label = "Choose Data"),
uiOutput('download_with_prettychbx')
)
)
server <- function(input, output, session) {
LineFile <- eventReactive(c(input$Line_Dataset), {
read_csv(input$Line_Dataset$datapath, col_names = T,)
})
observeEvent(input$Line_Dataset, {
elements_line_data <- LineFile() %>%
colnames()
output$download_with_prettychbx <- renderUI({
tagList(
prettyCheckboxGroup(
inputId = "Broken",
label = "Checkboxes with status",
choices = LineFile(),
inline = TRUE,
status = "danger",
shape = "round")
)
})})
}
shinyApp(ui,server)
推荐阅读
- asp.net-mvc - Html.ActionLink 返回无样式的 PartialView
- java - 访问对象内对象的设置器
- react-native - 在 React Native 中使用 ScrollViews 水平和垂直滚动
- android - 导航抽屉活动设计未正确显示
- mysql - MySQL:LOAD DATA LOCAL INFILE 添加了额外的字符 '\r'
- javascript - 在分页中禁用通过触摸滚动
- delphi - 循环而不导致应用程序冻结
- electron - Electron 在主进程中处理 console.log 消息
- html - 使用 bootstrap4 的可滚动表体
- powershell - 在 docker 上安装海拉德时出错