我试图在最近完成的一些定性数据分析的基础上创建一些动态输出。我需要用户做出一个选择,在闪闪发光。基于此,我需要使用SQLite在RQDA中运行一个查询。
我已经看过多个视频,关于重新激活输入的闪亮,但所有我试图应用的都没有发挥作用。我尝试使用SQLite ()和paste0()为我的查询创建一个文本块,但是using不允许我运行这个命令。
UI代码
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中的错误:不允许在没有活动反应上下文的情况下进行操作。(您试图做一些只能在反应性表达式或观察者中完成的事情。)这是我得到的错误信息-我知道我做了一些明显的错误,但我似乎看不到它!
发布于 2019-07-24 15:56:02
https://stackoverflow.com/questions/57150686
复制相似问题