そのため、コード内のロジックをさらに確認すると役に立ちます。一般的に言って、リアクティブ式がプログラム ロジックのコンテキストでどのように機能するかを理解することは非常に重要です。光沢のあるホームページのコードをできるだけ多く読んでみたいと思います。これは、私が書いた簡単なスクリプトであり、あなたが求めているものになると思います。乾杯。
Global.r
library(plyr)
library(dplyr)
exp <- data.frame(Ind=rep(c("a","b"),each=50),val1=rgamma(100,10,5),val2=rnorm(100,2,3.5))
サーバー.r
library(shiny)
library(ggvis)
shinyServer(function(input, output, session) {
output$selectO <- renderUI({ selectInput(inputId="selectI", label = h4("Level to Plot"),
choices = list("a","b","c"),selected="a")
})
observe({
if(!is.null(input$selectI)){
expfilter <- reactive({
vals <- exp %>% filter(Ind == input$selectI)
return(vals)
})
if(nrow(expfilter())==0){
fail <- reactive({ return("filter failed") })
output$trouble <- renderText({fail()}) # notice the use of () since fail is a function. when you want to grab the values of reactives use the ()
} else {
success <- reactive({ return("good") })
output$trouble <- renderText({success()})
P1 <- reactive({
expfilter %>% ggvis(~val1, ~val2) %>%
add_axis("x",title="Var1",title_offset=45,properties=axis_props(labels=list(fontSize = 13, fontWeight = "bold"),title=list(fontSize = 15))) %>%
add_axis("y",properties=axis_props(labels=list(fontSize = 13, fontWeight = "bold")))
})
P1 %>% bind_shiny("plot1")
}
}
})
})
ui.r
library(shiny)
shinyUI(fluidPage(
column(3,
wellPanel(
uiOutput("selectO")
)
),
column(9,
wellPanel(
ggvisOutput("plot1")),
wellPanel(h6("How Did the Filter Do"),
textOutput("trouble")
)
)
)
)