Skip to content

Instantly share code, notes, and snippets.

@randy3k

randy3k/app.R

Created Feb 12, 2020
Embed
What would you like to do?
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