【发布时间】:2018-11-08 02:12:24
【问题描述】:
背景
我有一个应用程序,用户从下拉菜单 (selectizeInput) 中选择一个文件名,然后使用 actionButton 确认选择。该应用程序将以DT::dataTableOutput 格式显示结果。
目标
我希望能够显示加载屏幕(使用 shinydashboardloader 包),但仅在用户按下 actionButton 之后。在此之前,我想显示一个空屏幕。此外,如果用户想在一个会话中尝试多个文件,则每次按下 actionButton 时都会出现加载屏幕,并在加载数据集时消失。
当前状态
目前,如果我运行这个应用程序,加载按钮会一直出现,在用户选择文件之前也是如此
### ui.R
library(shiny)
library(shinydashboard)
library(DT)
library(shinycustomloader)
dashboardPage(
dashboardHeader(),
dashboardSidebar(
selectizeInput("file", "Select File",
c("fileA", "fileB")),
actionButton("submit", "Submit")
),
dashboardBody(
fluidRow(
box(h2("My Data"),
div(style = 'overflow-x: scroll',
withLoader(DT::dataTableOutput('mytable'),
type = "html",
loader = "loader1")),
width = 12)
)
)
)
#### server.R
library(shiny)
library(shinydashboard)
library(DT)
shinyServer(function(input, output, session) {
file_name <- reactive({
req(input$file)
})
# When the Submit button is clicked, start the cleaning and matching
observeEvent(input$submit, {
## open chosen file
# open_file <- read_excel(paste0("input_files/", file_name()))
### + some processing that gives me matched_df
matched_df <- data.frame(A = c(1, 2, 3, 4),
B = c("A", "B", "C", "D"))
selected <- reactive({
matched_df # + apply some filter
})
output$mytable = DT::renderDataTable({
selected()
})
})
})
我猜测前进的方向是使用conditionalPanel,但我不确定如何点击actionButton 条件。
更新
我将conditionalPanel 应用于数据表,但它仅在我第一次按下“提交”按钮时才有效。如果在同一会话中更改文件名并再次按下按钮,加载程序将不会出现。有什么想法可以让它在一个会话中多次工作吗?
dashboardBody(
fluidRow(
box(h2("My Data"),
conditionalPanel("input.submit==1",
div(style = 'overflow-x: scroll',
withLoader(DT::dataTableOutput('mytable'),
type = "html",
loader = "loader1"))
),
width = 12)
任何帮助都会很棒,谢谢!
【问题讨论】:
标签: r shiny shinydashboard