在我的Shiny应用程序中,我想给用户删除数据的机会。 尽管查看了有关此主题的多个问题,但我找不到解决方案。
data("swiss")
swiss2 <- swiss
rownames_swiss2 <- rownames(swiss2)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
checkboxGroupInput(inputId = "var_4_linearModel", label = "Choose a variable",
choices = names(swiss2[c(1,2,3,5,6)]), width = '100%', selected = "Fertility"),
verbatimTextOutput(outputId = "summary_linearModel", placeholder = TRUE),
selectInput(inputId="selectedLeveragePoints", label = "select leverage points",
choices=rownames(swiss2), multiple = TRUE),
checkboxInput(inputId="adjustedModel", label = "view adjusted model", value = FALSE)
),
mainPanel(
verbatimTextOutput(outputId = "model")
)
)
)
server <- function(input, output) {
# get selected variables
variables <- reactive({ paste(input$var_4_linearModel, sep = " " , collapse = '+') })
#build model without selected points
#Error is probably somewhere here
leveragePoints <- reactive({ input$selectedLeveragePoints })
swissNoLeverage <- reactive({ swiss2[-which(rownames_swiss2 %in% leveragePoints() ),] })
noLeverageFormula <- reactive({ paste("swissNoLeverage$Education ~ ", variables()) })
noLeverageLinearModel <- reactive( {lm(noLeverageFormula(), data = swissNoLeverage()) })
# output model
testModel <- reactive(
if(!is.null(input$var_4_linearModel) && !is.null(input$selectedLeveragePoints) && (input$adjustedModel == TRUE)){
return(noLeverageLinearModel() )
} else {
print("select your model ")
})
output$model <- renderPrint({ summary(testModel()) })
}
shinyApp(ui=ui, server = server)
但是我希望能够删除数据点,但会收到错误消息“'closure'类型的对象不可子集化”
预先加油并感谢