केस स्टडीज़: R में Shiny के साथ वेब एप्लिकेशन बनाना
Dean Attali
Shiny Consultant
data <- gapminder
data <- subset(
data,
lifeExp >= input$life[1] & lifeExp <= input$life[2]
)
if (input$continent != "All") {
data <- subset(
data,
continent == input$continent
)
}
renderTable()renderPlot()downloadHandler()reactive() वैरिएबल्स इस्तेमाल करेंoutput$my_table <- renderTable({
data <- gapminder
data <- subset(
data,
lifeExp >= input$life[1] & lifeExp <= input$life[2]
)
})
my_data <- reactive({data <- gapminder data <- subset( data, lifeExp >= input$life[1] & lifeExp <= input$life[2] )})output$my_table <- renderTable({ my_data() })
output$table <- renderTable({
fit_model(input$num)
})
output$plot <- renderPlot({
ggplot(
fit_model(input$num), ...)
})
fit_model() में 5s लगता हैfit_model() दो बार कॉल = 10sx <- reactive({ fit_model(input$num) })output$table <- renderTable({ x() })output$plot <- renderPlot({ ggplot(x(), ...) })
x() दो बार कॉल होगा, लेकिन x के अंदर का कोड एक बार चलेगाfit_model() एक बार कॉल = 5sLazy वैरिएबल = मान की जरूरत पड़ने तक कैलकुलेट नहीं होता
x <- reactive({
fit_model(input$num)
})
output$download <- downloadHandler(
filename = "x.csv",
content = function(file) {
write.csv(x(), file)
}
)
x() तभी चलता है जब डाउनलोड माँगा जाए, हर बार input$num बदलने पर नहीं
केस स्टडीज़: R में Shiny के साथ वेब एप्लिकेशन बनाना