我正在尝试为数据库构建一个有点复杂的 CRUD 接口(创建、读取、更新和删除)(可能闪亮不是最好的工具,但我想尝试一下,因为我不熟悉 js)。我已经找到了一些很好的例子,特别是来自Barbara https://github.com/bborgesr/wsds2017。现在我正在寻找一种组合的快捷方式selectizeInput
and a textInput
(也许作为 selectize 的一个选项?!),因为否则如果我必须像下面的示例所示那样做,我的代码就会变得很长。这个例子将展示我想要得到什么。 (This https://stackoverflow.com/questions/36768785/shiny-update-input-text-for-select-input不是我要找的。)
这是一个非常简短的可重现示例:
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 town"),
selected = input$text
)
})
}
# Run the application
shinyApp(ui = ui, server = server)
对于一个更复杂的示例,我尝试实现一个简单的数据表来编辑,您可以在我的github https://github.com/frumentum/combineInputs帐户。希望有一个更短的方法这样做......