闪亮到 RQDA 查询

Shiny to RQDA queries

我正在尝试根据我最近完成的一些定性数据分析创建一些动态输出。我需要用户在 Shiny 中进行选择。基于此,我需要 运行 使用 SQLite 在 RQDA 中进行查询。

我看过多个关于在 Shiny 中重新激活输入的视频,但我尝试应用的所有内容都没有奏效。我尝试使用 paste() 和 paste0() 为我的查询创建 SQLite 命令的文本块,但闪亮不允许我 运行 这个。

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))
}

Warning: Error in .getReactiveEnvironment()$currentContext: Operation not allowed without an active reactive context. (You tried to do something that can only be done from inside a reactive expression or observer.) This is the error message I get - I know I'm doing something obviously wrong but I can't seem to see it!

我使用 Shiny 中的模块找到了我自己的问题的答案 - 我最近在 R 中发现了这些指向模块的链接,并基于此重建了我的 Shiny 应用程序,这一切似乎都很好 运行 .

Modularizing Shiny Apps Communication Between Modules

谢谢!