Vaka Çalışmaları: R ile Shiny Kullanarak Web Uygulamaları Geliştirme
Dean Attali
Shiny Consultant
x’in değeri değişince, x’e bağlı her şey yeniden değerlendirilirDüz R ile karşılaştırın:
x <- 5
y <- x + 1
x <- 10
y’nin değeri nedir? 6 mı 11 mi?
Bir render işlevinde input$<inputId> kullanımı çıktıyı yeniden üretir
output$my_plot <- renderPlot({
plot(rnorm( input$num ))
})
output$my_plot, input$num’a bağlıdır
input$num değişirse ⇒
output$my_plot tepki verir
render*() işlevi bir reaktif bağlamdırserver <- function(input, output) {
print(input$num)
}
ERROR: Operation not allowed without an active reactive context.
Reaktif değişkene erişmek için observe({ ... })
server <- function(input, output) {
observe({
print( input$num )
})
}
Hata ayıklama için yararlı, reaktif değişkeni izler
observe({
print( input$num1 )
print( input$num2 )
})
Reaktif değişken oluşturmak için reactive({ ... })
Yanlış:
server <- function(input, output) {
x <- input$num + 1
}
ERROR: Operation not allowed without an active reactive context.
Doğru:
server <- function(input, output) {
x <- reactive({
input$num + 1
})
}
()server <- function(input, output){
x <- reactive({
input$num + 1
})
observe({
print( input$num )
print( x() )
})
}
Vaka Çalışmaları: R ile Shiny Kullanarak Web Uygulamaları Geliştirme