Skip to content

Instantly share code, notes, and snippets.

@randy3k
Created February 12, 2020 00:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save randy3k/d17fd45d28713d90c2539ef5ebfec9d3 to your computer and use it in GitHub Desktop.
Save randy3k/d17fd45d28713d90c2539ef5ebfec9d3 to your computer and use it in GitHub Desktop.
shiny app with splite
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