r - 闪亮的 RQDA 查询
问题描述
我正在尝试根据我最近完成的一些定性数据分析来创建一些动态输出。我需要用户在 Shiny 中进行选择。基于此,我需要使用 SQLite 在 RQDA 中运行查询。
我看过多个关于在 Shiny 中重新激活输入的视频,但我尝试应用的所有内容都没有奏效。我尝试使用 paste() 和 paste0() 为我的查询创建 SQLite 命令的文本块,但闪亮不会让我运行它。
界面代码
library(shiny)
library(igraph)
library(sqldf)
library(RQDA)
library(DBI)
# Open the project
openProject("C:/SWOT Analysis/Qual Analysis of SWOTs.rqda")
# Get the table required for inputs
db <- dbConnect(SQLite(), dbname="Qual Analysis of SWOTs.rqda")
# Read in the inputs
codeCat <- dbReadTable(db, "codecat")[which(dbReadTable(db,"codecat")$status==1),c(3,1)]
# Set to a vector format for shiny
codeCat1 <- setNames(codeCat$catid, codeCat$name)
ui <- fluidPage(
tabsetPanel(
tabPanel(title = "2 Categories",
tags$h1("Compare two coded categories"),
wellPanel(selectInput(inputId = "Opt1",
label = "Select the first category",
choices = codeCat1,
selected = codeCat1[1]),
selectInput(inputId = "Opt2",
label = "Select the second category",
choices = codeCat1,
selected = codeCat1[2])),
textOutput(outputId = "cat2"),
plotOutput(outputId = "pcat2"),
tableOutput(outputId = "tbl")
)))
服务器代码
server <- function(input, output, session){
output$cat2 <- renderText({paste(input$Opt1, "and", input$Opt2, "have been selected.")})
a <- renderText({paste("SELECT codecat.name, freecode.name FROM codecat, freecode, treecode WHERE codecat.catid=treecode.catid AND freecode.id=treecode.cid AND treecode.status=1 and treecode.catid = ", input$Opt1, "or codecat.catid=treecode.catid AND freecode.id=treecode.cid AND
treecode.status=1 and treecode.catid = ", input$Opt2)})
# testing to see if the RQDA query works - this did
output$tbl <-renderTable({RQDAQuery(paste("SELECT codecat.name, freecode.name FROM codecat, freecode, treecode WHERE codecat.catid=treecode.catid AND freecode.id=treecode.cid AND treecode.status=1 and treecode.catid = ", input$Opt1, "or codecat.catid=treecode.catid AND freecode.id=treecode.cid AND
treecode.status=1 and treecode.catid = ", input$Opt2))})
# this will be used for plotting after doing clusters later
# edges <- RQDAQuery(a())
on.exit(DBI::dbDisconnect(db))
}
警告:.getReactiveEnvironment()$currentContext 中的错误:如果没有活动的反应上下文,则不允许操作。(您试图做一些只能从反应式表达式或观察者内部完成的事情。)这是我得到的错误消息 - 我知道我做的事情显然是错误的,但我似乎看不到它!
解决方案
我使用 Shiny 中的模块找到了我自己的问题的答案——我最近发现了这些指向 R 中模块的链接,并在此基础上重建了我的 Shiny 应用程序,一切似乎都运行良好。
谢谢!
推荐阅读
- java - ResourceResolverException:无法解析 ID Body 的元素
- r - 根据多列标准搜索 data.frame 索引 - 如何加快大型数据集?
- php - Comfile pi 不会从浏览器运行 python 脚本
- git - 如何在查找已合并到当前的分支时排除没有任何提交的新 git 分支?
- react-native - 如何垂直对齐到反应原生的中心导航选项?
- sql - 如何使用多个表进行 sql 查询,每个表都有 onde 条件?
- react-native - 您如何将图标添加到此选项卡导航器?
- reactjs - 获取当前位置后设置初始区域不起作用
- rest - 当 POST 请求没有正文并且服务器响应是 403 Forbidden 错误时,CORS 失败
- angular - 在(单击)和(焦点)事件上打开 Mat 对话框