Skip to content

Instantly share code, notes, and snippets.

@dsquintana
Created August 2, 2019 13:28
Show Gist options
  • Save dsquintana/3021accab18142ded3857f3e02439c1b to your computer and use it in GitHub Desktop.
Save dsquintana/3021accab18142ded3857f3e02439c1b to your computer and use it in GitHub Desktop.
library(shiny)
library(synthpop)
library(DT)
ui <- fluidPage(
titlePanel("Creating synthetic data"),
sidebarLayout(
sidebarPanel(
p("This is an application that creates default data synthesis using the 'synthpop' package. Upload some data and inspect the synthesized data. Your file must be in csv format to upload."),
fileInput(inputId = "datafile", label = "Upload a data file", multiple = FALSE, placeholder = "No file selected", accept = "csv"),
actionButton(inputId = "update", label = "Update"),
downloadButton("downloadData", "Download")
),
mainPanel(
h3("Synthesized dataset"),
plotOutput(outputId = "plot"),
dataTableOutput("table")
)
)
)
server <- function(input, output, session) {
contentsrea <- reactive({
inFile <- input$datafile
if (is.null(inFile))
return(NULL)
read.csv(inFile$datapath)
})
observeEvent(input$update, {
if(!is.null(input$datafile)){
df <- read.csv(input$datafile$datapath, header = TRUE, sep = ",")
synResult <- syn(df, seed = 1337)
df <- synResult$syn
com <- compare(synResult,df)
fig <- com$plots
output$plot <- renderPlot(fig)
output$table <- DT::renderDataTable(df, server = FALSE,
extensions = c("Buttons"),
options = list(dom = 'Bfrtip',
buttons = c('csv', 'excel')
))
}
})
}
runApp(list(ui=ui,server=server))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment