我不明白为什么以下代码无效:
library(shinyWidgets)
library(shiny)
library(tidyverse)
library(forcats)
tmp <- tibble(Cat = c(rep("IV", 5), rep("III", 5)),
Subcat = LETTERS[1:10])
tmp <- mutate(tmp, Cat = factor(Cat), Subcat = factor(Subcat))
ui <- fluidPage(
titlePanel(""),
sidebarLayout(
sidebarPanel(
checkboxGroupButtons("Cat", "Category:", choices = levels(tmp$Cat), selected = levels(tmp$Cat)),
uiOutput("Subcat")
),
mainPanel(tableOutput("Table"))
)
)
server <- function(input, output) {
output$Subcat <- renderUI({
tmp <- tmp %>%
filter(Cat %in% input$Cat) %>%
mutate(Subcat = fct_drop(Subcat))
# pickerInput("what", label = "hello?", choices = levels(tmp$Subcat), selected = levels(tmp$Subcat), multiple = TRUE) #Does not appear
checkboxGroupButtons("what", label = "hello?", choices = levels(tmp$Subcat), selected = levels(tmp$Subcat)) #Appears
})
output$Table <- renderTable({ filter(tmp, Cat %in% input$Cat, Subcat %in% input$what)})
}
shinyApp(ui = ui, server = server)
如果我取消注释pickerInput
行并注释掉以下行,则不会显示下拉窗口小部件。我做错了什么,或者我偶然发现了一个错误?
updatePickerInput()
。
答案 0 :(得分:2)
我在版本0.3.5上,一切都适合我。尝试安装开发版
# install.packages("devtools")
# devtools::install_github("dreamRs/shinyWidgets")
library(shinyWidgets)
library(shiny)
library(tidyverse)
library(forcats)
tmp <- tibble(Cat = c(rep("IV", 5), rep("III", 5)),
Subcat = LETTERS[1:10])
tmp <- mutate(tmp, Cat = factor(Cat), Subcat = factor(Subcat))
ui <- fluidPage(
titlePanel(""),
sidebarLayout(
sidebarPanel(
checkboxGroupButtons("Cat", "Category:", choices = levels(tmp$Cat), selected = levels(tmp$Cat)),
uiOutput("Subcat")
),
mainPanel(tableOutput("Table"))
)
)
server <- function(input, output) {
output$Subcat <- renderUI({
tmp <- tmp %>%
filter(Cat %in% input$Cat) %>%
mutate(Subcat = fct_drop(Subcat))
pickerInput("what", label = "hello?", choices = levels(tmp$Subcat), selected = levels(tmp$Subcat), multiple = TRUE) #Does not appear
})
output$Table <- renderTable({ filter(tmp, Cat %in% input$Cat, Subcat %in% input$what)})
}
shinyApp(ui = ui, server = server)