sugitora commited on
Commit
edae905
·
verified ·
1 Parent(s): 8e5759f

Upload 6 files

Browse files
Files changed (6) hide show
  1. DESCRIPTION +7 -0
  2. app.R +51 -47
  3. data/CCS_Act01.csv +0 -0
  4. data/CCS_Act02.csv +0 -0
  5. data/CCS_Act03.csv +0 -0
  6. install.R +1 -0
DESCRIPTION ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ Package: mycarbonapp
2
+ Package: CCSLawDB
3
+ Title: CCS Law Database Viewer
4
+ Version: 0.0.1
5
+ Description: Shiny app for viewing CCS-related legal data
6
+ Author: Your Name
7
+ License: MIT
app.R CHANGED
@@ -1,58 +1,62 @@
 
 
 
 
1
  library(shiny)
2
- library(bslib)
3
  library(dplyr)
4
- library(ggplot2)
5
 
6
- df <- readr::read_csv("penguins.csv")
7
- # Find subset of columns that are suitable for scatter plot
8
- df_num <- df |> select(where(is.numeric), -Year)
 
9
 
10
- ui <- page_sidebar(
11
- theme = bs_theme(bootswatch = "minty"),
12
- title = "Penguins explorer",
13
- sidebar = sidebar(
14
- varSelectInput("xvar", "X variable", df_num, selected = "Bill Length (mm)"),
15
- varSelectInput("yvar", "Y variable", df_num, selected = "Bill Depth (mm)"),
16
- checkboxGroupInput("species", "Filter by species",
17
- choices = unique(df$Species), selected = unique(df$Species)
 
 
 
 
 
18
  ),
19
- hr(), # Add a horizontal rule
20
- checkboxInput("by_species", "Show species", TRUE),
21
- checkboxInput("show_margins", "Show marginal plots", TRUE),
22
- checkboxInput("smooth", "Add smoother"),
23
- ),
24
- plotOutput("scatter")
25
  )
26
 
 
27
  server <- function(input, output, session) {
28
- subsetted <- reactive({
29
- req(input$species)
30
- df |> filter(Species %in% input$species)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  })
32
-
33
- output$scatter <- renderPlot(
34
- {
35
- p <- ggplot(subsetted(), aes(!!input$xvar, !!input$yvar)) +
36
- theme_light() +
37
- list(
38
- theme(legend.position = "bottom"),
39
- if (input$by_species) aes(color = Species),
40
- geom_point(),
41
- if (input$smooth) geom_smooth()
42
- )
43
-
44
- if (input$show_margins) {
45
- margin_type <- if (input$by_species) "density" else "histogram"
46
- p <- p |> ggExtra::ggMarginal(
47
- type = margin_type, margins = "both",
48
- size = 8, groupColour = input$by_species, groupFill = input$by_species
49
- )
50
- }
51
-
52
- p
53
- },
54
- res = 100
55
- )
56
  }
57
 
58
- shinyApp(ui, server)
 
 
1
+ if (!requireNamespace("DT", quietly = TRUE)) {
2
+ stop("DT package not available")
3
+ }
4
+
5
  library(shiny)
6
+ library(DT)
7
  library(dplyr)
8
+ library(readr)
9
 
10
+ # ファイル読み込み
11
+ act01 <- read_csv("data/CCS_Act01.csv") %>% mutate(法分類 = "法律")
12
+ act02 <- read_csv("data/CCS_Act02.csv") %>% mutate(法分類 = "政令")
13
+ act03 <- read_csv("data/CCS_Act03.csv") %>% mutate(法分類 = "省令")
14
 
15
+ # データ統合
16
+ law_data <- bind_rows(act01, act02, act03)
17
+
18
+ # UI定義
19
+ ui <- fluidPage(
20
+ titlePanel("法令データベース検索(CCS法体系プロトタイプ)"),
21
+ sidebarLayout(
22
+ sidebarPanel(
23
+ selectInput("law_type", "法分類を選択:",
24
+ choices = c("すべて", unique(law_data$法分類)),
25
+ selected = "すべて"),
26
+ textInput("keyword", "キーワード検索:", ""),
27
+ actionButton("search", "検索実行")
28
  ),
29
+ mainPanel(
30
+ DTOutput("table")
31
+ )
32
+ )
 
 
33
  )
34
 
35
+ # サーバ定義
36
  server <- function(input, output, session) {
37
+
38
+ filtered_data <- eventReactive(input$search, {
39
+ data <- law_data
40
+
41
+ if (input$law_type != "すべて") {
42
+ data <- filter(data, 法分類 == input$law_type)
43
+ }
44
+
45
+ if (input$keyword != "") {
46
+ data <- filter(data, grepl(input$keyword, 条文テキスト, ignore.case = TRUE))
47
+ }
48
+
49
+ data
50
+ }, ignoreNULL = FALSE)
51
+
52
+ output$table <- renderDT({
53
+ datatable(
54
+ filtered_data(),
55
+ options = list(pageLength = 15, autoWidth = TRUE),
56
+ rownames = FALSE
57
+ )
58
  })
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  }
60
 
61
+ # アプリ起動
62
+ shinyApp(ui = ui, server = server)
data/CCS_Act01.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/CCS_Act02.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/CCS_Act03.csv ADDED
The diff for this file is too large to render. See raw diff
 
install.R ADDED
@@ -0,0 +1 @@
 
 
1
+ install.packages(c("shiny", "DT", "dplyr", "readr"), repos = "https://cloud.r-project.org")