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

आउटपुट के लिए placeholders जोड़ना

आउटपुट वे ऑब्जेक्ट होते हैं जिन्हें यूज़र को दिखाया जाना है और जो R में जनरेट होते हैं, जैसे कोई प्लॉट या टेबल.

Shiny ऐप में कोई आउटपुट जोड़ने के लिए, सबसे पहले आपको उसके लिए एक placeholder जोड़ना होता है, जो Shiny को यह बताता है कि आउटपुट को कहाँ रखना है.

Shiny अलग‑अलग प्रकार के आउटपुट के लिए कई placeholder फंक्शन देता है. उदाहरण के लिए, plotOutput() प्लॉट दिखाने के लिए है, tableOutput() टेबल आउटपुट के लिए है, और textOutput() डायनामिक टेक्स्ट के लिए है.

यह अभ्यास पाठ्यक्रम का हिस्सा है

केस स्टडीज़: R में Shiny के साथ वेब एप्लिकेशन बनाना

पाठ्यक्रम देखें

अभ्यास निर्देश

  • साइडबार पैनल में "name" ID के साथ एक text input बनाएँ.
  • मेन पैनल में तीन आउटपुट placeholders जोड़ें:
    • "greeting" ID वाला text output (लाइन 14).
    • "cars_plot" ID वाला plot output (लाइन 16).
    • "iris_table" ID वाला table output (लाइन 18).

इंटरैक्टिव व्यावहारिक अभ्यास

इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।

library(shiny)

# Define UI for the application
ui <- fluidPage(
  sidebarLayout(
    sidebarPanel(
      # Create a text input with an ID of "name"
      ___(___, "What is your name?", "Dean"),
      numericInput("num", "Number of flowers to show data for",
                   10, 1, nrow(iris))
    ),
    mainPanel(
      # Add a placeholder for a text output with ID "greeting"
      textOutput(outputId = ___),
      # Add a placeholder for a plot with ID "cars_plot"
      ___("cars_plot"),
      # Add a placeholder for a table with ID "iris_table"
      ___(___)
    )
  )
)

# Define the server logic
server <- function(input, output) {}

# Run the application
shinyApp(ui = ui, server = server)
कोड संपादित करें और चलाएँ