Skip to content

Instantly share code, notes, and snippets.

@yonicd

yonicd/app.R

Created Oct 12, 2020
Embed
What would you like to do?
app example
library(whereami)
library(ggplot2)
if(!file.exists('cars.csv')){
readr::write_csv(mtcars,path = 'cars.csv')
}
# Define the UI
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
fileInput("file1", "Choose CSV File",
accept = c(
"text/csv",
"text/comma-separated-values,text/plain",
".csv")
),
tags$hr(),
shiny::uiOutput('xcol'),
shiny::uiOutput('ycol')
),
mainPanel(
shiny::plotOutput('plot')
)
)
)
# Define the server code
server <- function(input, output) {
dat <- eventReactive(input$file1,{
inFile <- input$file1
if (is.null(inFile))
return(NULL)
read.csv(inFile$datapath)
})
output$xcol <- renderUI({
this_dat <- dat()
shiny::selectizeInput(
inputId = 'x',
label = 'Select Column',
choices = names(this_dat),
selected = names(this_dat)[1]
)
})
output$ycol <- renderUI({
this_dat <- dat()
shiny::selectizeInput(
inputId = 'y',
label = 'Select Column',
choices = names(this_dat),
selected = names(this_dat)[1]
)
})
output$plot <- shiny::renderPlot({
whereami::cat_where(whereami::whereami(tag = 'hist'))
dat()%>%
ggplot(aes(x = !!rlang::sym(input$x), y = !!rlang::sym(input$y))) + geom_point()
})
}
# Return a Shiny app object
shinyApp(ui = ui, server = server)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment