sqlite를 이용한 shiny app 만들기
sqlite를 이용한 shiny app 만들기
sqlite를 이용한 shiny app 만들기
SQLite를 연동하는 간단한 Shiny app을 만든 예제이다.
1
2
3
4
default:
db:
db_name: "db/penguins.db"
tbl_name: "penguins"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
pacman::p_load(
"shiny", "shinydashboard",
"pool", "DBI", "RSQLite", "DT",
"tidyverse",
"config"
)
db <- config::get("db")
db_name <- db$db_name
tbl_name <- db$tbl_name
con <- dbConnect(
SQLite(),
dbname = db_name
)
source("ui.R")
source("server.R")
shinyApp(ui = ui, server = server)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
ui <- dashboardPage(
# header ------------------------------------------------------------------
dashboardHeader(
title = "Uni-Demo"
), # dashboardHeader (
# sidebar -----------------------------------------------------------------
dashboardSidebar(
sidebarMenu(
menuItem("Penquins Table", tabName = "tab_pg_tbl", icon = icon("dashboard"))
) # sidebarMenu(
), # dashboardSidebar(
# body --------------------------------------------------------------------
dashboardBody(
# tab_pg_tbl --------------------------------------------------------------
tabItems(
# First tab content
tabItem(tabName = "tab_pg_tbl",
fluidRow(
column(width = 12,
dataTableOutput("pg_tbl")
)
)
) # tabItem(tabName = "dashboard",
) # tabItems(
) # dashboardBody(
)
1
2
3
4
5
6
7
8
9
server <- function(input, output, session) {
get_data <- reactive({
dbReadTable(con, tbl_name)
})
output$pg_tbl <- renderDataTable({
datatable(get_data())
})
} # server
Demo: https://yeonkyupark.shinyapps.io/uni-demo/
참고자료
This post is licensed under CC BY 4.0 by the author.