0

这是我第一次使用闪亮。我建立了一个数据库来提供现有的应用程序。我创建的新模块(通过修改 by_country 页面太复杂了)并且没有完全工作。

表格“tablepreped.xlsx”正在显示,下拉菜单也是如此,但是当我更改选择器时,表格的过滤不会更新。

基本上,我想选择一个指标,并在此基础上在我的表格中过滤国家名称、差距大小和差距值,理想情况下还能够选择差距大小。如果有人能指出我正确的方向,我将不胜感激!

server <- function(input, output, session) {

  observeEvent(input$go_to_aimm_landing, {

    hideElement("main_app")
    showElement("landing_page")

  })

  observeEvent(landing_page_return$page_selected_trigger(), {

    page_ <- landing_page_return$page_selected()

    updateNavbarPage(
      session,
      "nav_pages",
      selected = page_
    )

  landing_page_return <- callModule(
    landing_page_module,
    "landing_page_id"
  )

  by_country_return <- callModule(
    by_country_module,
    'by_country',
    indicator_dat = dat,
    rank_ranges = band_ranges,
    defaults = landing_page_return$default_selected
  )

  callModule(
    by_size_module,
    'by_size'
  )

  callModule(
    map_module,
    'map_id',
    default_selected = landing_page_return$default_selected
  )
}

服务器

by_size_module_ui <- function(id) {
  ns <- NS(id)

  tabsetPanel(
    tabPanel(
      "Indicators",
      fluidRow(
        br(),
        column(
          width = 10,
          fluidRow(
            column(
              width = 12,
              tagList(
                fluidRow(
                  column(
                    width = 2,
                    pickerInput(
                      ns("country"),
                      "Country",
                      choices = choices$country,
                      selected = "Tanzania",
                      options = list(
                        'live-search' = TRUE,
                        'live-search-placeholder' = 'Search...',
                        'live-search-normalize' = TRUE,
                        'live-search-style' = 'contains'
                      ),
                      width = "100%"
                    )
                  ),
                  column(
                    width = 4,
                    pickerInput(
                      ns("indicator_names"),
                      "Indicator",
                      choices = choices$indicator_names,
                      selected = "Adult account holders",
                      options = list(
                        'live-search' = TRUE,
                        'live-search-placeholder' = 'Search...',
                        'live-search-normalize' = TRUE,
                        'live-search-style' = 'contains'
                      ),
                      width = "100%"
                    )
                  ),
                  column(
                    width = 2,
                    pickerInput(
                      ns("indicator_type"),
                      "Type of Indicator",
                      choices = choices$indicator_type,
                      choicesOpt = list(
                        disabled = c("gap", "intensity") %in% c("intensity")
                      ),
                      selected = "gap",
                      multiple = TRUE,
                      options = pickerOptions(
                        actionsBox = TRUE,
                        liveSearch = TRUE,
                        liveSearchPlaceholder = 'Search...',
                        liveSearchNormalize = TRUE,
                        liveSearchStyle = 'contains'
                      ),
                      width = "100%"
                    )
                  ),
                  column(
                    width = 2,
                    pickerInput(
                      ns("gap_size"),
                      "Gap Size",
                      choices = choices$gap_size,
                      selected = "l",
                      multiple = TRUE,
                      options = pickerOptions(
                        actionsBox = TRUE,
                        liveSearch = TRUE,
                        liveSearchPlaceholder = 'Search...',
                        liveSearchNormalize = TRUE,
                        liveSearchStyle = 'contains'
                      ),
                      width = "100%"
                    )
                  )
                )
              )
            ),
            column(
              width = 12,
              h2(
                style = "margin-left: 5px; margin-top: 25px; white-space: nowrap;",
                "Indicator: ",
                textOutput(ns("sel_indicator_name"), inline = TRUE)
              )
            )
          )
        )
      ),

      tagList(DTOutput(ns("by_size_table")) %>%
          withSpinner(),
        tags$script(src = "by_country_time_series.js"),
        tags$script(paste0("by_country_module_js('", ns(''), "')"))
      ),
      br(),
      br()
    )
  )
}

by_size_module <- function(input, output, session, tablepreped, default_selected) {
  ns <- session$ns

  default_selected <- reactive({

    list(
      default_indicator_name = input$indicator_names,
      default_country = input$country,
      default_gap_size = input$gap_size,
      default_indicator_type = input$indicator_type
    )

  })


  ### GAP Ranges table ----------
  library('datasets')
  library("openxlsx")
  tablepreped <- read.xlsx("tablepreped.xlsx")

##Makes title reactive to indicator input
  indoc <- reactive({
    sel_indicator_name <- input$indicator_names

  })

  output$sel_indicator_name <- renderText({
    indoc()
  })


  # filter data for the selected indicator and gap size
  tablepreped_filtered <- reactive({
    gsize<-input$gap_size

    hold<-input$indicator_names

    hold_gap_size <- hold %>%
      dplyr::filter(gap_size == gsize)

    ctry_indicator_values <- hold_gap_size %>%
      select(country, gap_vals,gap_size)


  })

  # create data frame

    out <- tablepreped

    out<-out %>%
        select(
        country,
        indicator_name,
        gap_vals,
        gap_size
      )

  output$by_size_table <- DT::renderDataTable({
    DT::datatable(out,
                  rownames = FALSE,
                  class = "compact stripe",
                  options = list(orderClasses = TRUE)
                  )
  })
}

这是数据帧头

structure(list(country = c("Afghanistan", "Afghanistan", "Afghanistan", 
"Afghanistan", "Afghanistan", "Afghanistan"), code = c("gap_ind_0001", 
"gap_ind_0002", "gap_ind_0003", "gap_ind_0005", "gap_ind_0006", 
"gap_ind_0007"), indicator_name = c("Affordability ", 
"Infrastructure", "Poverty Rate", 
"Adjusted years of schooling", "Adult literacy", 
"Account holders, female"), s = c(70, 60, 67, 8, 58.2, 
55), m = c(60, 45, 50, 7, 39.5, 34.9), l = c(45, 30, 30, 5, 26, 
21.5), gap_size = c("vl", "l", "m", "vl", "s", "vl"), gap_vals = c(29.58082, 
23.3432, 18.330012, 4.87, 14.893313, 7.160684)), row.names = c(NA, 
6L), class = "data.frame")
4

0 回答 0