始める無料で始める

レイアウト(UI)を更新する

Shinylayout 関数を使うと、UI 要素を配置できます。ここでは sidebarLayout() を使い、入力は sidebarPanel() に、出力は mainPanel() に置きます。次のテンプレートを使ってアプリのレイアウトを更新しましょう。

sidebarLayout(
  sidebarPanel(p("This goes into the sidebar on the left")),
  mainPanel(p("This goes into the panel on the right"))
)

shinyggplot2 パッケージはあらかじめ読み込んであります。p('hello') は、テキスト "hello" を含む HTML の段落要素を返すことに注意してください。

この演習はコースの一部です

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

コースを見る

演習の手順

  • textInput()sidebarPanel() の中に置きます。
  • plotOutput()mainPanel() の中に置きます。
  • 両方のパネルをサイドバーのレイアウトに入れます:sidebarLayout(___ , ___)

実践的なインタラクティブ演習

このサンプルコードを完成させて、この演習に挑戦してみましょう。

ui <- fluidPage(
  titlePanel("Baby Name Explorer"),
  # CODE BELOW: Add a sidebarLayout, sidebarPanel, and mainPanel
  
  textInput('name', 'Enter Name', 'David'),
  plotOutput('trend')
  
)

server <- function(input, output, session) {
  output$trend <- renderPlot({
    ggplot()
  })
}

shinyApp(ui = ui, server = server)
コードを編集して実行