我有一個閃亮的應用程序使用UpdateselectInput,我想添加一個actionButton,因爲有一些bug單獨updateselectInput。 它似乎沒有工作,我要顯示該表只如果我操作的按鈕 我的應用程序是與此類似:在一個閃亮的應用程序中使用actionButton和updateSelectInput
library(shiny)
library(dplyr)
library(DT)
ui <- fluidPage(
titlePanel("Title"),
sidebarLayout(
sidebarPanel(width=3,
selectInput("filter1", "Filter 1", multiple = TRUE, choices = c("All", LETTERS)),
selectInput("filter2", "Filter 2", multiple = TRUE, choices = c("All", as.character(seq.int(1, length(letters), 1)))),
selectInput("filter3", "Filter 3", multiple = TRUE, choices = c("All", letters)),
actionButton("go_button", "GO !")),
mainPanel(
DT::dataTableOutput("tableprint")
)
)
)
server <- function(input, output, session) {
output$tableprint <- DT::renderDataTable({
input$go_button
# Data
df <- tibble(LETTERS = rep(LETTERS, 2), Numbers = as.character(1:52),
letters = paste(LETTERS, Numbers, sep = ""))
df1 <- df
if("All" %in% input$filter1){
df1
} else if (length(input$filter1)){
df1 <- df1[which(df1$LETTERS %in% input$filter1),]
}
# Update selectInput choices based on the filtered data. Update 'selected' to reflect the user input.
updateSelectInput(session, "filter1", choices = c("All", df$LETTERS), selected = input$filter1)
updateSelectInput(session, "filter2", choices = c("All", df1$Numbers), selected = input$filter2)
if("All" %in% input$filter2){
df1
} else if (length(input$filter2)){
df1 <- df1[which(df1$Numbers %in% input$filter2),]
}
updateSelectInput(session, "filter3", choices = c("All", df1$letters), selected = input$filter3)
if("All" %in% input$filter3){
df1
} else if (length(input$filter3)){
df1 <- df1[which(df1$letters %in% input$filter3),]
}
datatable(df1)
})
}
# Run the application
shinyApp(ui = ui, server = server)
感謝您的幫助!
不太清楚你在找什麼。你想添加一個新的'actionButton'並且只在你點擊按鈕時才顯示錶格嗎?另外'updateSelectInput'有什麼問題? – krish
是的,我只想點擊按鈕就顯示我的表格。但在我的例子中,該表自動... 我的真實數據是相當大的,當我過濾它時,出現了一些錯誤,當我嘗試改變變量篩選器中的模態時,應用程序卡住了,我必須關閉它來解決問題。我認爲一個動作按鈕可以完成這項工作 –