Update layout (UI)
You can use layout functions provided by Shiny to arrange the UI elements. In this case, we want to use a sidebarLayout(), where the input is placed inside a sidebarPanel() and the output is placed inside the mainPanel(). You can use this template to update the layout of your app.
sidebarLayout(
sidebarPanel(p("This goes into the sidebar on the left")),
mainPanel(p("This goes into the panel on the right"))
)
We have pre-loaded the shiny and ggplot2 packages for you. Note that p('hello') returns an HTML paragraph with the text "hello".
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
Building Web Applications with Shiny in R
คำแนะนำการฝึกหัด
- Place the
textInput()inside asidebarPanel(). - Place the
plotOutput()inside amainPanel(). - Place both panels inside a sidebar layout:
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)