r - 如何在 Shiny App 中正确创建反应性数据集列表?
问题描述
我目前有几个不同的反应数据集,它们是由我的 Shiny 应用程序创建的,并且正在尝试构建一个函数来拉取适当的数据集和renderHTML
. 我目前正在努力对我正在创建的这个反应数据集列表进行子集化。
我尝试使用listofsurveydata
下面的反应性数据集列表 ( ),但总是收到Error in .subset2: no such index at level 1
错误消息。
lcSurveyDataSplit <- function(panelnumber){
colind <- grep(input$lcstateselect[panelnumber],colnames(inputTable$data))
predata <- inputTable$data %>%
filter(
grepl(search,.[[colind]]),
is.null(input$lccategoryselect)| Category %in% input$lccategoryselect,
is.null(input$lcsubcategoryselect)| Sub_category %in% input$lcsubcategoryselect,
is.null(input$lcquestionselect)| Question %in% input$lcquestionselect
)
}
lcsurveydata1 <- reactive({lcSurveyDataSplit(1)})
lcsurveydata2 <- reactive({lcSurveyDataSplit(2)})
lcsurveydata3 <- reactive({lcSurveyDataSplit(3)})
lcsurveydata4 <- reactive({lcSurveyDataSplit(4)})
lcSplitPanel <- function(panelnumber){ # sfnumber stands for "surveyFunction number"
listofsurveydata <- list(lcsurveydata1(), lcsurveydata2(), lcsurveydata3(), lcsurveydata4())
surveyFunction <- listofsurveydata[[panelnumber]]
questioncount <- nrow(surveyFunction)
state <- grep(input$lcstateselect[panelnumber], colnames(inputTable$data))
survey <- character(0)
i = 1
while (i <= questioncount) {
category = surveyFunction[i,2]
subcategory = surveyFunction[i,3]
question = surveyFunction[i,4]
answer = gsub("[\r\n]", "</br>", surveyFunction[i,state])
if (length(grep(category,survey, fixed = T)) > 0) {
survey <- paste0(survey,"</br>",
"</br><b>", subcategory, "</b>",
"</br><b>", question, "</b>",
"</br><i>", answer, "</i>","</br>")
} else {
survey <- paste0(survey,"</br>",
"<b><u>",category, "</u></b>",
"</br></br><b>", subcategory, "</b>",
"</br><b>", question, "</b>",
"</br><i>", answer, "</i>","</br>")
}
i = i + 1
}
HTML(paste0("<h4><b>",input$lcstateselect[panelnumber],"</b></h4>",survey))
}
output$lcstate1 <- renderUI({lcSplitPanel(1)})
output$lcstate2 <- renderUI({lcSplitPanel(2)})
output$lcstate3 <- renderUI({lcSplitPanel(3)})
output$lcstate4 <- renderUI({lcSplitPanel(4)})
我已经能够将错误缩小到这两行,因为如果我不对数据进行子集化并对数据集进行字面引用,则代码可以正常工作listofsurveydata
:
listofsurveydata <- list(lcsurveydata1(), lcsurveydata2(), lcsurveydata3(), lcsurveydata4())
surveyFunction <- listofsurveydata[[panelnumber]]
理想情况下,我不想为每个输出对象创建一个新函数,所以我想知道应该如何解决这个错误?
解决方案
推荐阅读
- python - 分组依据的值计数不显示熊猫中 null/NA 值的计数
- neo4j - 使用 Python 将数据导入 Neo4j 需要时间
- sql - 如何在表和列相同的一行中获得两个不同的值
- android - 此代码如何引发 NoWhenBranchMatchedException?
- html - 背景图片将填充 2 div
- azure-active-directory - 在 $select 中指定时,组 delta 查询不返回成员
- ios - 如何在不制作 IBOutlet 的情况下以编程方式在 Swift 中为 UIView 高度约束设置动画?
- angular - 数据未从 html 传入 API
- javascript - 如何使用jquery复制备用表中的表行
- android - 在不使用 ACCESS_NETWORK_STATE 的情况下检查 Internet