我正在尝试为数据库(创建,读取,更新和删除)构建一个稍微复杂的CRUD接口(可能闪亮不是解决此问题的最佳工具,但由于我不熟悉js,因此我想尝试一下)。我已经找到了一些很好的例子,特别是Barbara的例子。现在,我正在寻找一种组合a selectizeInput和a 的快捷方式textInput(也许是selectize的选项?!),因为否则,如果我必须像下面的示例所示进行操作,那么我的代码就会变得很长。该示例将演示我想要得到的。(这不是我想要的。)
这是一个非常短的可重现示例:
library(shiny)
startData <- c("Berlin", "London", "Paris")
ui <- fluidPage(
selectizeInput("town", "Town", choices = c(startData, "new town")),
uiOutput("newTown")
)
server <- function(input, output, session) {
rV <- reactiveValues(towns = startData)
output$newTown <- renderUI({
if (input$town == "new town") {
tagList(
textInput("text", "New Town"),
actionButton("entry", "save town")
)
}
})
# update selectizeInput when actionButton is clicked
observeEvent(input$entry, {
rV$towns <- c(rV$towns, input$text)
updateSelectizeInput(
session, "town", "Town",
choices = c(rV$towns, "new …Run Code Online (Sandbox Code Playgroud)