gpt4 book ai didi

r - Shiny App checkboxInput 和 conditionalPanel

转载 作者:行者123 更新时间:2023-12-04 11:22:03 24 4
gpt4 key购买 nike

我是 ShinyApp 的新手。

我想将 checkboxInput() 与 conditionalPanel 一起使用,所以当它被选中时,类型的选项将显示出来(然后用户可以从“啤酒”、“提神”、“烈酒”、“酒”中选择一个类型)。如果未选中,则不会显示类型选项。

下面是我的代码,但是无论我是否选中该框,当类型选项都没有显示时。我想我应该在服务器功能中写点什么?我真的不知道。感谢您的帮助。

  ui <- fluidPage(
titlePanel("BC Liquor Store prices"),
img(src = "BCLS.png",align = "right"),
sidebarLayout(
sidebarPanel(sliderInput("priceInput", "Price", 0, 100, c(25, 40), pre = "$"),

wellPanel(
checkboxInput("checkbox", "Filter by Type", FALSE),
conditionalPanel(
condition="checkbox==true",
selectInput("typeInput", "Product type",
choices = c("BEER", "REFRESHMENT", "SPIRITS", "WINE"),
selected = "WINE")
)
),

uiOutput("countryOutput")

),
mainPanel(
tabsetPanel(
tabPanel("Plot", plotOutput("coolplot")),
tabPanel("Summary", verbatimTextOutput("summary")),
tabPanel("Table", tableOutput("results"))
)
)
)
)

server <- function(input, output, session) {
output$countryOutput <- renderUI({
selectInput("countryInput", "Country",
sort(unique(bcl$Country)),
selected = "CANADA")
})

filtered <- reactive({
if (is.null(input$countryInput)) {
return(NULL)
}

bcl %>%
filter(Price >= input$priceInput[1],
Price <= input$priceInput[2],
Type == input$typeInput,
Country == input$countryInput
)
})

output$coolplot <- renderPlot({
if (is.null(filtered())) {
return()
}
filtered() %>% ggvis(~Alcohol_Content, fill := "#fff8dc") %>%
layer_histograms(width = 1, center = 0)
})

output$results <- renderTable({
filtered()
})
}

最佳答案

我最近在研究类似的 one 时遇到了这个问题。 .

似乎 checkboxInput 条件的简单答案如下:
condition="input.checkbox==1",

关于r - Shiny App checkboxInput 和 conditionalPanel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34115076/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com