Hello,
I've been working on building up modules and I'm trying to pass the output of the module as a dataframe to reactive values that I can use as my next step calculation. However, it keeps throwing out this error to me "object of type 'closure' is not subsettable", which makes frustrated for a while.
I've been googling and trying to identify the problem. it seems that when creating an object such as a list, dataframe or vector using the reactive() function, I must include parentheses. However, I tried everywhere and it still seems not working.
This is where the problem arises...
counter1_cal_rate <- reactiveValues()
observe({
counter1_cal_rate$data <- upload_rate_counter1$data %>%
cal_rate_fcn()
})
Can someone help me on this? Any help is much much appreciated! I really need help on this!!!
thank you!!!
#Load packages
library(shiny)
library(data.table)
library(dplyr, warn.conflicts = FALSE)
library(DT)
#>
#> Attaching package: 'DT'
#> The following objects are masked from 'package:shiny':
#>
#> dataTableOutput, renderDataTable
library(tidyr)
library(lubridate, warn.conflicts = FALSE)
### Module for Uploaded Rate
modFunction_Upload_Rate <- function(input, output, session, data) {
v <- reactiveValues(data = NULL)
observeEvent(data(), {
v$data <- data()
})
output$Upload_Rate <- DT::renderDataTable({
req(v$data)
DT::datatable(v$data) %>%
formatPercentage(c(6:ncol(v$data)), 2)
})
}
modFunctionUI_Upload_Rate <- function(id) {
ns <- NS(id)
DT::dataTableOutput(ns("Upload_Rate"))
}
shinyApp(
ui = fluidPage(
fluidRow(
fileInput("file1", "Choose CSV File",
multiple = FALSE,
accept = c("text/csv",
"text/comma-separated-values,text/plain",
".csv"))
),
fluidRow(
modFunctionUI_Upload_Rate("counter1_rate_table"),
DT::dataTableOutput("counter1_rate_cal_table")
)
),
server = function(input, output, session) {
counter1_con_rate<-reactive({
req(input$file1)
counter1<-fread(input$file1$datapath, header = TRUE, sep = ",", stringsAsFactors = FALSE)
counter_rate_fcn(counter1)
})
upload_rate_counter1 <- callModule(modFunction_Upload_Rate, "counter1_rate_table",counter1_con_rate)
# Problem starts here
counter1_cal_rate <- reactiveValues()
observe({
counter1_cal_rate$data <- upload_rate_counter1$data %>%
cal_rate_fcn()
})
output$counter1_rate_cal_table <- DT::renderDataTable({
req(counter1_cal_rate$data)
DT::datatable(counter1_cal_rate$data) %>%
formatPercentage(c(6:ncol(counter1_cal_rate$data)), 2)
})
}
)
Shiny applications not supported in static R Markdown documents
Created on 2020-12-17 by the reprex package (v0.3.0)
...