babynames エクスプローラーの Shiny アプリを作る

Rで作るShiny Webアプリケーション

Ramnath Vaidyanathan

VP of Product Research

アプリをスケッチする

赤ちゃんの名前の推移を表示するアプリのラフスケッチのようなコンピュータ作画図

Rで作るShiny Webアプリケーション

入力を追加(UI)

ui <- fluidPage(

titlePanel("Baby Name Explorer"),
textInput('name', 'Enter Name', 'David')
)
server <- function(input, output, session){

}
shinyApp(ui = ui, server = server)

タイトル「Baby name explorer」と名前「David」の入力がある Web アプリ

Rで作るShiny Webアプリケーション

出力を追加(UI/server)

ui <- fluidPage(
  titlePanel("Baby Name Explorer"),
  textInput('name', 'Enter Name', 'David'),

plotOutput('trend')
)
server <- function(input, output, session){

output$trend <- renderPlot({ ggplot() })
}
shinyApp(ui = ui, server = server)
Rで作るShiny Webアプリケーション

出力を追加(UI/server)

タイトル「Baby names explorer」、名前「David」の入力、空のプロットが表示された Web アプリ

Rで作るShiny Webアプリケーション

レイアウトを更新(UI)

ui <- fluidPage(
  titlePanel("Baby Name Explorer"),

sidebarLayout(
sidebarPanel(
textInput('name', 'Enter Name', 'David')
),
mainPanel(
plotOutput('trend')
)
)
)
server <- function(input, output, session){
  output$trend <- renderPlot({ggplot()})
}
Rで作るShiny Webアプリケーション

レイアウトを更新(UI)

タイトル「Baby names explorer」、名前「David」の入力、左に入力・右に空のプロットがある Web アプリ

Rで作るShiny Webアプリケーション

出力を更新(server)

ui <- fluidPage(
  ...
)
server <- function(input, output, session){
  output$trend <- renderPlot({

data_name <- subset( babynames, name == input$name )
ggplot(data_name) + geom_line( aes(x = year, y = prop, color = sex) )
}) }

タイトル「Baby names explorer」、名前「David」の入力、左に入力・右に時系列の頻度プロットが表示された Web アプリ

Rで作るShiny Webアプリケーション

Passons à la pratique !

Rで作るShiny Webアプリケーション

Preparing Video For Download...