I've tried everything to define the new columne before adding it to the reactive formula, it still throws me an error. It worked fine when before I put into the shiny format
#library(shiny)
ui <- fluidPage( "PROJECT REKT ( CDI TOOL)" , selectInput( inputId ="State" , label = "Choose your client's state", c( "AK","AL","AZ",
"AR", "CA", "CO", "CT", "DE", "FL", "GA",
"HI", "ID", "IL", "IN", "IA", "KS", "KY",
"LA", "ME", "MD", "MA", "MI", "MN", "MS",
"MO", "MT", "NE", "NV", "NH", "NJ", "NM",
"NY", 'NC', 'ND', 'OH', 'OK', 'OR', "PA",
"RI", "SC", "SD", "TN", "TX", "UT", "VT",
"VA", "WA", "WV", "WI", "WY"), multiple = FALSE, selectize=TRUE , width = NULL , size = NULL)
)
server <- function(input, output) {
data2 = renderTable(National_data[National_data$state == input$State,])
#data2$captureRate = NULL
# Summarize the data by each acuity group ( like aa pivot table), uset SetNames to rename columns
#data3 = cast(data2 , num_is_wo + num_is_cc + num_is_mcc ~ acuity_group, mean)
data4 = reactive(
setNames (aggregate(list(data2()$num_is_cc , data2()$num_is_mcc, data2()$num_is_wo), by=list(data2()$acuity_group), FUN=sum, na.rm=TRUE) , c ("acuity_group","cc","mcc", "wo"))
)
# Find the capture rate for each row element
data4$captureRate = NULL
data4$captureRate = reactive(
(data4()$cc + data4()$mcc) / (data4()$wo + data4()$cc + data4()$mcc)
)
State_BM_CaptureRate = reactive (
mean(data4()$captureRate, na.rm = TRUE)
)
Output$bencmark = State_BM_CaptureRate
}
shinyApp(ui = ui, server = server)
Which results in
Listening on http://127.0.0.1:7136
Warning: Error in =: object of type 'closure' is not subsettable
Stack trace (innermost first):
45: server [#16]
4: <Anonymous>
3: do.call
2: print.shiny.appobj
1: <Promise>
Error in data4$captureRate = NULL :
object of type 'closure' is not subsettable