オープンデータとプログラミング

Shinyチュートリアル(レッスン3) ウィジェットを追加する

コントロールウィジェットをShinyアプリケーションに追加します。
ウィジェットは利用者のメッセージをShinyアプリケーションに通知します。

なお、この記事は
http://shiny.rstudio.com/tutorial/lesson3/をもとに作成しています。

まずは画面イメージを。

すべてのウィジェットを並べると、こんな感じになります。

widget

用意されているウィジェットの関数は次のとおりです。

基本的な機能はこのウィジェットでほぼ対応できてしまいます。

関数 ウィジェット
actionButton Action Button
checkboxGroupInput A group of check boxes
checkboxInput A single check box
dateInput A calendar to aid date selection
dateRangeInput A pair of calendars for selecting a date range
fileInput A file upload control wizard
helpText Help text that can be added to an input form
numericInput A field to enter numbers
radioButtons A set of radio buttons
selectInput A box with choices to select from
sliderInput A slider bar
submitButton A submit button
textInput A field to enter text

ウィジェットを追加する

レッスン2でやったようにHTMLコンテンツを追加するのとどうようのやり方でsidebarPanelやmainPanelにウィジェットを追加することができます。

サンプルソースは以下のとおりです。

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# ui.R
 
shinyUI(fluidPage(
  titlePanel("Basic widgets"),
   
  fluidRow(
     
    column(3,
      h3("Buttons"),
      actionButton("action", label = "Action"),
      br(),
      br(),
      submitButton("Submit")),
     
    column(3,
      h3("Single checkbox"),
      checkboxInput("checkbox", label = "Choice A", value = TRUE)),
     
    column(3,
      checkboxGroupInput("checkGroup",
        label = h3("Checkbox group"),
        choices = list("Choice 1" = 1,
           "Choice 2" = 2, "Choice 3" = 3),
        selected = 1)),
     
    column(3,
      dateInput("date",
        label = h3("Date input"),
        value = "2014-01-01"))  
  ),
   
  fluidRow(
     
    column(3,
      dateRangeInput("dates", label = h3("Date range"))),
     
    column(3,
      fileInput("file", label = h3("File input"))),
     
    column(3,
      h3("Help text"),
      helpText("Note: help text isn't a true widget,",
        "but it provides an easy way to add text to",
        "accompany other widgets.")),
     
    column(3,
      numericInput("num",
        label = h3("Numeric input"),
        value = 1))  
  ),
     
  fluidRow(
     
    column(3,
      radioButtons("radio", label = h3("Radio buttons"),
        choices = list("Choice 1" = 1, "Choice 2" = 2,
                       "Choice 3" = 3),selected = 1)),
     
    column(3,
      selectInput("select", label = h3("Select box"),
        choices = list("Choice 1" = 1, "Choice 2" = 2,
                       "Choice 3" = 3), selected = 1)),
     
    column(3,
      sliderInput("slider1", label = h3("Sliders"),
        min = 0, max = 100, value = 50),
      sliderInput("slider2", "",
        min = 0, max = 100, value = c(25, 75))
      ),
     
    column(3,
      textInput("text", label = h3("Text input"),
        value = "Enter text..."))  
  )
 
))

Comments are closed.