library(shiny)
library(ggplot2)
library(ggstatsplot)
#Repo and installation instructions: https://github.com/IndrajeetPatil/ggstatsplot
library(psych)
ui <- pageWithSidebar(
headerPanel("The App"),
sidebarPanel(width = 3,
#-------------Fileupload----------------------------------
fileInput('file1', 'Choose CSV File',
accept=c('text/csv','text/comma-separated-values,text/plain','.csv')),
#-------------Other sidebar menus-------------------------
checkboxInput('header', 'Do you have Header row?', TRUE),
tags$hr(), #Horizontal separator
includeScript("../../../Matomo-tquant.js"),
fluidRow(
# column(6,checkboxGroupInput("xvar","Var1:", c("1"="1","2"="2"))),
# column(6,checkboxGroupInput("yvar","Var2:", c("1"="1","2"="2")))
column(6,radioButtons("xvar","Var1:", c("1"="1","2"="2"))),
column(6,radioButtons("yvar","Var2:", c("1"="1","2"="2")))
)
),
#-------------Mainpanel content---------------------------
mainPanel(
h3(textOutput('caption')), #---- "Load Data"----- message
tabsetPanel(
tabPanel("Data", tableOutput('contents'), style = "height:500px; overflow-y: scroll;overflow-x: scroll;"),
tabPanel("Summary",verbatimTextOutput("summary")),
tabPanel("Histoscatter",plotOutput("plot1")),
tabPanel("Group Comparison",plotOutput("plot2"))
)
)
)
server <- function(input, output,session) {
#-------------Data manipulation---------------------------
dsnames <- c()
data_set <- reactive({
inFile <- input$file1
if (is.null(inFile))
return()
data_set<-read.csv(inFile$datapath, header=input$header)
})
#-------------Render table and create choices-----------
output$contents <- renderTable({data_set()})
observe({
dsnames <- names(data_set())
cb_options <- list()
cb_options[ dsnames] <- dsnames
# updateCheckboxGroupInput(session, "xvar",
# label = "Var1",
# choices = cb_options,
# selected = "")
# updateCheckboxGroupInput(session, "yvar",
# label = "Var2",
# choices = cb_options,
# selected = "")
updateRadioButtons(session, "xvar",
label = "Var1",
choices = cb_options,
selected = "")
updateRadioButtons(session, "yvar",
label = "Var2",
choices = cb_options,
selected = "")
})
#-----------------PLOT'S---------------------------------
#-----------------Plot 1---------------------------------
output$plot1 <- renderPlot({
ggstatsplot::ggscatterstats(data = data_set(),
x = input$xvar,
y = input$yvar,
#title = "Sample dataset",
messages = FALSE)
})
#-----------------Plot 2--------------------------------
output$plot2 <- renderPlot({
ggstatsplot::ggbetweenstats(data = data_set(),
x = input$xvar,
y = input$yvar,
#title = "Sample dataset",
messages = FALSE)
})
#-----------------Summary-------------------------------
output$summary <- renderPrint({
describe(data_set())
})
#-----------------Plot 4--------------------------------
#----------------Load Data message---------------------
output$caption<-renderText({
if(is.null(input$file1)) { "Begin by loading a CSV file" } else { "Data Loaded ... choose variables"}
})
}
shinyApp(ui, server)