플롯을 더 크게 만들기
입력 함수가 입력 유형에 따라 서로 다른 인수를 가질 수 있듯이, 출력 플레이스홀더 함수도 모양이나 동작을 바꾸기 위한 서로 다른 인수를 가질 수 있어요.
예를 들어 Shiny 앱에서 plotOutput()를 사용해 플롯을 표시하면, 기본 높이는 400픽셀입니다. plotOutput() 함수에는 플롯의 높이나 너비를 수정할 수 있는 몇 가지 매개변수가 있어요.
이 연습은 강의의 일부입니다
사례 연구: R의 Shiny로 웹 애플리케이션 만들기
연습 안내
직전 연습 문제의 Shiny 앱 코드가 제공되어 있습니다. 여러분의 작업은 플롯을 더 크게 만드는 것입니다. 구체적으로는:
- 높이 600픽셀, 너비 600픽셀로 설정하세요. 어떤 매개변수를 써야 하는지는
plotOutput()문서(18번째 줄)를 참고하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
textInput("title", "Title", "GDP vs life exp"),
numericInput("size", "Point size", 1, 1),
checkboxInput("fit", "Add line of best fit", FALSE),
colourInput("color", "Point color", value = "blue"),
selectInput("continents", "Continents",
choices = levels(gapminder$continent),
multiple = TRUE,
selected = "Europe"),
sliderInput("years", "Years",
min(gapminder$year), max(gapminder$year),
value = c(1977, 2002))
),
mainPanel(
# Make the plot 600 pixels wide and 600 pixels tall
plotOutput("plot", ___, ___)
)
)
)
# Define the server logic
server <- function(input, output) {
output$plot <- renderPlot({
data <- subset(gapminder,
continent %in% input$continents &
year >= input$years[1] & year <= input$years[2])
p <- ggplot(data, aes(gdpPercap, lifeExp)) +
geom_point(size = input$size, col = input$color) +
scale_x_log10() +
ggtitle(input$title)
if (input$fit) {
p <- p + geom_smooth(method = "lm")
}
p
})
}
shinyApp(ui = ui, server = server)