I'm trying to load a script from a seminar on meta analysis, which supposedly gives you an app/tool to run meta analysis. The script looks like this:
if(!require(shiny)){install.packages('shiny')}
if(!require(shinythemes)){install.packages('shinythemes')}
if(!require(rstudioapi)){install.packages('rstudioapi')}
library(shiny)
library(shinythemes)
ui <- fluidPage(theme=shinytheme("flatly"),
titlePanel("Mini meta-analysis of your own studies (correlations)"),
sidebarLayout(
sidebarPanel(
h6("To create the mini meta-analysis, you need to upload a CSV file with the following columns:"),
h6("Study: Name of the study/experiment [String]"),
h6("N : Sample size"),
h6("R : Correlation between X and Y"),
fileInput("file1", "Choose CSV File",
accept = c(
"text/csv",
"text/comma-separated-values,text/plain",
".csv"))
),
mainPanel(h3("Loaded file:"), br(),
tableOutput("fileload"), br(),
h3("Meta analysis Results:"), br(),
h5(verbatimTextOutput("metaresult")), br(),
plotOutput("forestplot"),br(),
plotOutput("funnelplot"),br(),
h3("Test for asymmetry & trim-fill procedure"), br(),
h5(verbatimTextOutput("metaresult3")), br(),
h5(verbatimTextOutput("metaresult2")), br(),
plotOutput("funnelplottrim"))
)
)
server <- function(input, output) {
this.dir <- dirname(rstudioapi::getActiveDocumentContext()$path)
setwd(this.dir)
source("minimetacor.R")
InFile <- reactive({
validate(
need(input$file1, "Choose a file to see meta-analysis output results!")
)
inFile <- input$file1
if (is.null(inFile))
return(NULL)
idataset <- read.table(inFile$datapath, header=TRUE, sep=",", na.strings="NA", dec=".", strip.white=TRUE)
})
MetaFile <- reactive({
idata <-InFile()
odataset<-CorMeta(idata$R, idata$N,idata$Study)
})
output$forestplot <- renderPlot({
PrintPlotMetaR(MetaFile())
})
output$metaresult <- renderPrint({
summary(MetaFile())
})
output$metaresult2 <- renderPrint({
taf <- trimfill(MetaFile())
taf
})
output$metaresult3 <- renderPrint({
regtest(MetaFile())
})
output$fileload <- renderTable({
InFile()
})
output$funnelplot <- renderPlot({
PrintFunnelMetaR(MetaFile())
})
output$funnelplottrim <- renderPlot({
taf <- trimfill(MetaFile())
taf
PrintFunnelMetaR(taf)
})
}
shinyApp(ui = ui, server = server)
However when I ran it, it briefly showed what I wanted, then gave me this error:
Listening on http://127.0.0.1:4427 Warning: Error in setwd: cannot change working directory 50: setwd 49: server [#4] Error in setwd(this.dir) : cannot change working directory
I'm not sure what this means. I assume its referring to this specific part of the code, however, I'm not sure if I should fiddle with this:
this.dir <- dirname(rstudioapi::getActiveDocumentContext()$path)
setwd(this.dir)
source("minimetacor.R")
Can anybody offer some insight? I don't wanna edit the wrong thing and it becomes unworkable.
It looks like I just needed to download another file, the "minimetacor" file shown in this directory code I mentioned:
Once I downloaded both the minimetacor file and downloaded the script I was using, I put them in the same folder and ran the script again. It worked right away.
Thanks to MrFlick for the help!