【问题标题】:Reset tableoutput with action button in shinydashboard使用闪亮仪表板中的操作按钮重置表输出
【发布时间】:2018-02-20 16:57:00
【问题描述】:

我有一个闪亮的仪表板应用程序,该应用程序有一个过滤器框和一个选项卡集,它们根据过滤器显示一个数据表。 我有一个重置按钮,它使用 shinyjs::reset 函数重置过滤器,我还想重置表格集并显示完整的表格或什么也不显示。 我也想为 valueboxes 做这件事。

我的应用是这样的:

对于服务器接口,我有一个基本的:output$tableprint_A <- DT::renderDataRable ({}) 界面:

body <- dashboardBody(
  tabItems(
    #### First tab item #####
    tabItem(tabName = "fpc",
            fluidRow(
              infoBoxOutput("kpm_inf", width = 6),
              infoBoxOutput(outputId = "fpc_inf", width = 6)
            ),
            fluidRow(
              box(title = "Variables filter",
                  shinyjs::useShinyjs(),
                  id = "side_panel",
                  br(),
                  background = "light-blue",
                  solidHeader = TRUE,
                  width = 2,
                  selectInput("aaa", "aaa", multiple = T, choices = c("All", as.character(unique(fpc$aaa))))
                  br(),
                  br(),
                  p(class = "text-center", div(style = "display:inline-block", actionButton("go_button", "Search", 
                                                                                            icon = icon("arrow-circle-o-right"))),
                    div(style = "display:inline-block", actionButton("reset_button", "Reset", 
                                                                     icon = icon("repeat")))),
                  p(class = 'text-center', downloadButton('dl_fpc', 'Download Data'))),
              tabBox(
                title = tagList(),
                id = "tabset1",
                width = 10,
                tabPanel(
                  "A \u2030 ",
                  DT::dataTableOutput("tableprint_A"),
                  bsModal(id = 'startupModal', title = 'Update message', trigger = '',
                          size = 'large',
                          tags$p(tags$h2("Last update of A : 01/09/2017",
                                         br(), br(),
                                         "Last update of B : 01/09/2017",
                                         br(), br(),
                                         "Last update of C : 01/09/2017",
                                         style = "color:green", align = "center")))
                ),
                tabPanel(
                  "B % Table",
                  DT::dataTableOutput("tableprint_B")),
                type = "pills"
              )
            ),
            fluidRow(
              # Dynamic valueBoxes
              valueBoxOutput("info_gen", width = 6)
            )

我试过这个:

  observeEvent(input$reset_button, {
    output$tableprint_A <- NULL
  })

编辑:

我想要这样的东西,但是当我操作搜索按钮时,我希望它再次出现:

 shinyjs::onclick("reset_button",
                   shinyjs::toggle(id = "tableprint_A", anim = TRUE))

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    你应该试试这个:

    output$tableprint_A <- renderDataTable({
      if(input$reset_button == 1) {
        NULL
      }else{
        datatable(...)
      }
    })
    

    如果单击按钮,则不会显示任何内容,否则会显示datatable

    [编辑]

    library(shiny)
    library(DT)
    shinyApp(
      ui = fluidPage(selectInput("select", "select", choices = unique(iris$Species), multiple = T),
                     actionButton("go_button", "Search", 
                                  icon = icon("arrow-circle-o-right")),
                     actionButton("reset_button", "Reset", 
                                  icon = icon("repeat")),
                                  DT::dataTableOutput('tbl')),
      server = function(input, output) {
    
        values <- reactiveValues(matrix = NULL)
    
        observe({
          if (input$go_button == 0)
            return()
          values$matrix <- iris[iris$Species %in% input$select, ]
        })
        observe({
          if (input$reset_button == 0)
            return()
          values$matrix <- NULL
        })
    
        output$tbl = DT::renderDataTable({
          datatable(values$matrix, options = list(lengthChange = FALSE))}
        )
      }
    )
    

    【讨论】:

    • 谢谢,这正是我想要的!
    • 不完全是,当我做一个新的过滤器时它只工作了 1 次它什么也没显示
    • 你能解释一下这是什么意思:当我做一个新的过滤器时?
    • 当我在点击 reset_button 后过滤我的表时,它并没有给我一个新表,而是 NULL
    • 重置按钮正在清理过滤器框和数据表,但是当我想用新过滤器显示表格时,它在输出中没有给出任何内容
    猜你喜欢
    • 2015-12-12
    • 2018-08-02
    • 2018-02-24
    • 2021-03-21
    • 2015-04-22
    • 2019-04-19
    • 2019-06-18
    • 2019-07-02
    • 1970-01-01
    相关资源
    最近更新 更多