gpt4 book ai didi

css - 可写的 selectInput 选择器

转载 作者:行者123 更新时间:2023-11-28 02:40:34 25 4
gpt4 key购买 nike

我想以“可写”的方式修改我的 selectInput。例如,“位置”包含阿姆斯特丹、鹿特丹、海牙等。我想实现一个“可写”的输入选择器。因此,当有人写“Ams..”或“Amster...”时,会显示符合此条件的可能位置。有人能帮帮我吗?提前谢谢你。

这是我简化的 ui 部分:

library(DT)
library(shiny)
library(shinydashboard)

Location = c("Amsterdam","Amsterdam","Amsterdam","Rotterdam","Rotterdam","Rotterdam","Den Haag","Den Haag","Den Haag")
Year = c(2015,2014,2016,2015,2016,2016,2017,2016,2014)
Person = c("John", "Ann", "Katy", "Ann", "Katy", "William", "Henry", "Luke", "Luke")
mockup = data.frame(Location, Year, Person)

ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(
sidebarMenu(
menuItem("Selection", tabName = "selection")
)
),
dashboardBody(
tabItems(
tabItem(tabName = "selection",
fluidRow(
box(width = 5,
title = "TITLE", "Choose something",
collapsible = FALSE,
htmlOutput("Location_selector"),
htmlOutput("Year_selector")
),
mainPanel(
DT::dataTableOutput("selection")
)
))

)
)
)

这是我的服务器部分:

    server <- function(input, output, session) {

output$Location_selector = renderUI({
selectInput(inputId = "Location",
label = "Location:",
choices = sort(as.character(unique(mockup$Location))))
})
output$Year_selector = renderUI({

data_available = mockup[mockup$Location == input$Location, "Year"]

selectInput(inputId = "Year",
label = "Year:",
choices = sort(unique(data_available)),
selected = unique(data_available)[1])
})

}

shinyApp(ui, server)

最佳答案

我在 SO 上找到了我自己的问题的答案。我通过添加一个空选项 ("") 调整了服务器部分的“选择”部分:

server <- function(input, output, session) {

output$Location_selector = renderUI({
selectInput(inputId = "Location",
label = "Location:",
choices = c("", (sort(as.character(unique(mockup$Location))))))
})
}

shinyApp(ui, server)

关于css - 可写的 selectInput 选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47197859/

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