我正在嘗試使用 updateSelectizeInput 來更新使用 textInput 的選定選項。我試過粘貼輸入,但只更新了第一個值。我想輸入“A”、“B”、“C”作為文本,以便 selectizeInput 也反映這些值。現在選擇輸入框中只顯示“A”。
例子:

代碼:
library(shiny)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
textInput("text1", label = "Type (A, B, C)")
),
mainPanel(
selectizeInput("select1", choices = c("A", "B", "C"), label = "Select", multiple = TRUE,
options = list(
delimiter = ',',
create = I("function(input, callback){
return {
value: input,
text: input
};
}")
)),
textOutput("select_output")
)
)
)
server <- function(input, output, session) {
observeEvent(input$text1, {
updateSelectizeInput(session, "select1", selected = paste(input$text1))
})
output$select_output <- renderText({
input$select1
})
}
shinyApp(ui, server)
uj5u.com熱心網友回復:
您需要將向量傳遞給selectedin updateSelectizeInput,input$text1是一個字串。
嘗試 -
library(shiny)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
textInput("text1", label = "Type (A, B, C)")
),
mainPanel(
selectizeInput("select1", choices = c("A", "B", "C"), label = "Select", multiple = TRUE,
options = list(
delimiter = ','
)),
textOutput("select_output")
)
)
)
server <- function(input, output, session) {
observeEvent(input$text1, {
updateSelectizeInput(session, "select1", selected = unlist(strsplit(input$text1, ',\\s ')))
})
output$select_output <- renderText({
input$select1
})
}
shinyApp(ui, server)

轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/336885.html
上一篇:根據密鑰中的常見字符復制檔案
