開始使用免費開始

更新版面配置(UI)

你可以使用 Shiny 提供的 layout 函式來安排 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 建立網頁應用程式

檢視課程

練習說明

  • 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)
編輯並執行程式碼