開始使用免費開始

加入輸出(UI/Server)

接下來要在你的應用程式中加入一個空白圖表作為佔位。回想一下,若要把指派給物件 x 的圖表 p 加到 Shiny 應用程式中,你需要:

  1. 使用 renderPlot({p}) 來繪製圖表物件。
  2. 將繪製出的圖表指定給 output$x
  3. 在 UI 中用 plotOutput("x") 顯示圖表。

shinyggplot2 套件已為你預先載入。

本練習屬於課程

使用 R 的 Shiny 建立網頁應用程式

檢視課程

練習說明

  • ggplot() 建立一個空白圖表,將它 render,並指定到名為 'trend' 的 output。
  • 在 UI 中顯示這個圖表。記得在 textInput() 後面加逗號。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

ui <- fluidPage(
  textInput('name', 'Enter Name', 'David')
  # CODE BELOW: Display the plot output named 'trend'
  
)

server <- function(input, output, session) {
  # CODE BELOW: Render an empty plot and assign to output named 'trend'
  
  
  
}

shinyApp(ui = ui, server = server)
編輯並執行程式碼