我想這是你在找什麼:
我使用的數據集如下。我從csv
文件中加載了相同的數據。
autoFillDF <- structure(list(Name = c("ABC", "XYZ", "PQR"), Age = c(30L, 24L,
27L), Grade = c("A", "B", "D")), .Names = c("Name", "Age", "Grade"
), class = "data.frame", row.names = c(NA, -3L))
ui.R代碼
shinyUI(fluidPage(
titlePanel("Auto Fill"),
sidebarPanel(
selectizeInput("p1", choices = autoFillDF$Name, selected = NULL, label = 'Name'),
selectizeInput("p2", choices = NULL, label = 'Age'),
selectizeInput("p3", choices = NULL, label = 'Grade')
),
mainPanel(
DT::dataTableOutput('table')
)
)
)
server.R代碼
autoFillDF <- read.csv('..../test.csv', stringsAsFactors = FALSE)
shinyServer(function(input, output, session) {
updateApp <- reactive({
data <- autoFillDF
data <- data[data$Name %in% input$p1,]
updateSelectizeInput(session, 'p2', choices = data$Age, selected = data$Age, server = TRUE)
updateSelectizeInput(session, 'p3', choices = data$Grade, selected = data$Grade, server = TRUE)
data
})
output$table <- DT::renderDataTable(
DT::datatable(updateApp())
)
})
感謝完美的答案。真的解決了這個問題。 –
@ElvinMitchellToro,如果此答案有助於解決您的問題,請使用投票箭頭下的複選標記考慮[標記爲已接受](https://stackoverflow.com/help/someone-answers)。 – krish