केस स्टडीज़: R में Shiny के साथ वेब एप्लिकेशन बनाना
Dean Attali
Shiny Consultant
x का मान बदलता है, तो x पर निर्भर सब कुछ फिर से इवैल्युएट होता हैरेगुलर R से अंतर:
x <- 5
y <- x + 1
x <- 10
y का मान क्या है? 6 या 11?
render फंक्शन के अंदर input$<inputId> आउटपुट को री-रेंडर कराता है
output$my_plot <- renderPlot({
plot(rnorm( input$num ))
})
output$my_plot input$num पर निर्भर है
input$num बदले ⇒
output$my_plot react करता है
render*() फंक्शन एक reactive context हैserver <- function(input, output) {
print(input$num)
}
ERROR: Operation not allowed without an active reactive context.
Reactive वैरिएबल एक्सेस करने के लिए observe({ ... }) उपयोग करें
server <- function(input, output) {
observe({
print( input$num )
})
}
डिबगिंग में उपयोगी, reactive वैरिएबल ट्रैक करें
observe({
print( input$num1 )
print( input$num2 )
})
Reactive वैरिएबल बनाने के लिए reactive({ ... }) उपयोग करें
गलत:
server <- function(input, output) {
x <- input$num + 1
}
ERROR: Operation not allowed without an active reactive context.
सही:
server <- function(input, output) {
x <- reactive({
input$num + 1
})
}
() जोड़ेंserver <- function(input, output){
x <- reactive({
input$num + 1
})
observe({
print( input$num )
print( x() )
})
}
केस स्टडीज़: R में Shiny के साथ वेब एप्लिकेशन बनाना