शुरू करेंमुफ़्त में शुरू करें

अपने प्लॉट को बड़ा बनाना

जैसे इनपुट फंक्शन अलग-अलग इनपुट टाइप के अनुसार भिन्न आर्ग्युमेंट्स ले सकते हैं, वैसे ही आउटपुट प्लेसहोल्डर फंक्शन भी अपनी उपस्थिति या व्यवहार बदलने के लिए अलग आर्ग्युमेंट्स ले सकते हैं.

उदाहरण के लिए, जब 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)
कोड संपादित करें और चलाएँ