在将新柱子添加到反应式之前,我已经尝试了一切来定义新柱子,它仍然会让我错误。在我投入闪亮的格式之前,它工作得很好
#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)
结果是
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
答案 0 :(得分:0)
如果没有任何数据样本,很难假设,但初看起来我认为问题出在这一部分:
data4$captureRate = reactive(
(data4()$cc + data4()$mcc) / (data4()$wo + data4()$cc + data4()$mcc)
)
此时data4
是一个反应对象!因此,您无法使用data4$captureRate
!你如何解决它:
data4 <- reactive({
data <- 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"))
data$captureRate <- (data$cc + data$mcc) / (data$wo + data$cc + data$mcc)
data})