Vaka Çalışmaları: R ile Shiny Kullanarak Web Uygulamaları Geliştirme
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() değişkenleri kullanınoutput$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() 5 sn sürerfit_model() iki kez çağrılır = 10 snx <- reactive({ fit_model(input$num) })output$table <- renderTable({ x() })output$plot <- renderPlot({ ggplot(x(), ...) })
x() iki kez çağrılır, x içindeki kod bir kez çalışırfit_model() bir kez çağrılır = 5 snTembel değişken = değere ihtiyaç duyulana kadar hesaplanmaz
x <- reactive({
fit_model(input$num)
})
output$download <- downloadHandler(
filename = "x.csv",
content = function(file) {
write.csv(x(), file)
}
)
x() yalnızca indirme istendiğinde çalışır; input$num her değiştiğinde değil
Vaka Çalışmaları: R ile Shiny Kullanarak Web Uygulamaları Geliştirme