Created
October 12, 2020 20:27
-
-
Save yonicd/7e92c964cc3270a53d2f02f121ad24e7 to your computer and use it in GitHub Desktop.
app example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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