Created
February 12, 2020 00:35
-
-
Save randy3k/d17fd45d28713d90c2539ef5ebfec9d3 to your computer and use it in GitHub Desktop.
shiny app with splite
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(shiny) | |
library(tidyverse) | |
library(DBI) | |
con <- dbConnect(RSQLite::SQLite(), dbname = "mtcars.sqlite") | |
onStop(function() dbDisconnect(con)) | |
# to create the .sqlite file | |
# con %>% dbWriteTable("mtcars", mtcars) | |
ui <- fluidPage( | |
sidebarLayout( | |
selectInput("cyl", "Number of Cylinders:", c(4, 6, 8)), | |
mainPanel( | |
plotOutput("distPlot") | |
) | |
) | |
) | |
server <- function(input, output) { | |
output$distPlot <- renderPlot({ | |
x <- input$cyl | |
df <- con %>% | |
tbl("mtcars") %>% | |
filter(cyl == x) %>% | |
collect() | |
ggplot(df) + geom_point(aes(x = wt, y = mpg)) | |
}) | |
} | |
shinyApp(ui = ui, server = server) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment