R闪亮的应用程序模块

时间:2018-07-19 23:00:45

标签: r shiny

我正在尝试实现闪亮的模块,因为我意识到服务器和ui文件即将崩溃。这是我的理解,我有三个文件UI.r,server.r和module.r

但是当我尝试它时,出现以下错误。有人可以告诉我这里闪亮模块的实现有什么问题。

##UI.r
library(shiny)
library(shinydashboard)
library(plotly)
source("module.R")

sidebar <- dashboardSidebar(sidebarMenu(
  menuItem("Topline",tabName = "topline")))

body <-   ## Body content
  dashboardBody(tabItems(
    tabItem(tabName = "atc_topline",
                      fluidRow( tags$br(),
                      column(3, uiOutput("class_level"))),
                      fluidRow(chartTableBoxUI(id = "topline")) # render the tabBox inside a fluidRow
  ))
# Pt them together into a dashboardPage
dashboardPage(
  dashboardHeader(title = "Scorecard"),
  sidebar,
  body
)

Server.r

## Server.r
library(shiny)
library(dplyr)
library(knitr)
library(kableExtra)
library(plotly)
library(tidyr)
library(zoo)
library(plyr)
library(tidyverse)
source("module.R")

shinyServer(function(input, output) {
    MyData <- read.csv(file="ldb_data.csv", header=TRUE, sep=",")
    callModule(chartTableBox, id = "topline", data = MyData, class_group = "ATC Topline")

})

模块

##module.r
chartTableBoxUI <- function(id, div_width = "col-md-9") {
  ns <- NS(id)

  div(class = div_width,
      tabBox(
        width = 12,
        title = id,
        # tabPanel(icon("bar-chart"),
        #          plotlyOutput(ns("chart") )
        # ),
        tabPanel(icon("table"),
                 DT::dataTableOutput(ns("table")))
      ))

}

chartTableBox <-
  function(input, output, session, data, class_group) {
    module_data <- data %>% filter(category == class_group)

    module_data$Month_considered  <-as.character(module_data$Month_considered)
    module_data$Month_considered[which(module_data$Month_considered == "2/1/18")] <-"Feb-18"
    module_data$Month_considered  <-as.factor(module_data$Month_considered)



    # Drop-down selection box for which Classification Level to be selected
    output$class_level <- renderUI({
      selectInput(
        "selected_class",
        label = h4("Classification Level"),
        choices = list(
          "11 " = "1",
          "22 " = "2",
          "33" = "3",
          "44" = "4"
        )
      )
    })

    #### TOPLINE #####
        a <- reactive({
      module_data %>%
        filter(Tab == input$selected_class) %>%
        #filter(Classification_Level == input$selected_class & Primary_family == input$selected_product & Metric_name == input$selected_metric) %>%
        mutate(`ATC_Count` = Metric_Value) %>%
        mutate(`pct` = as.numeric(as.character(Metric_Value)) * 100) %>%
        select(Month_considered, `pct`) %>%
        group_by(Month_considered)
    })

    #arrange(Month_considered)

    b <- reactive({
      module_data %>%
        filter(Tab == input$selected_class) %>%
        #filter(Tab == "ATC Count" & Classification_Level == input$selected_class & Primary_family == input$selected_product) %>%
        group_by(Month_considered) %>%
        mutate(`ATC_Count` = Metric_Value) %>%
        select(Month_considered, `ATC_Count`)
    })
    #arrange(Month_considered)

    dt_data <- reactive({
      (inner_join(a(), b()))
    })


    # output$chart <- renderPlotly({
    #
    #   plot_ly(dt_data(), x = ~Month_considered, y = ~pct, type = 'scatter',mode = 'marker',fill = 'tozeroy',line = list(color = 'rgb(205, 12, 24)', width = 4))
    #
    # })

    output$table <- renderDataTable({
      DT::datatable(
        dt_data(),
        style = "bootstrap",
        class = "display",
        options = list(scrollX = TRUE, dom = 't')
      ) %>%
        formatPercentage('percent', 0)

    })

  }

错误:

Warning: Error in filter_impl: Evaluation error: object 'category' not found.
  69: <Anonymous>
Error in filter_impl(.data, quo) : 
  Evaluation error: object 'category' not found.

0 个答案:

没有答案