所以它會一直有助於查看代碼中的更多邏輯。我想我會說一般情況下,瞭解被動表達式在程序邏輯上如何工作是非常重要的。我會盡量在閃亮的主頁上閱讀儘可能多的代碼。這是我寫的一個快速腳本,我認爲可以得到你所問的內容。乾杯。
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))
Server.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")
)
)
)
)
我也對此感興趣。我只是有條件地提供一個data.frame與相同的列和零。你應該可以在ui.R中使用'conditionalPanel'來查看反應字符串,該字符串指示data.frame是否爲空,但它並不總是適用於我的情況。 – ideamotor 2014-09-23 19:03:45
您的「此處」鏈接對我來說是有幫助的。我還會查看她在評論中工作的應用程序的鏈接。你的UI有輸入控件嗎?您應該測試那些存在於server.r – miles2know 2014-09-25 02:01:08
@ miles2know謝謝指向評論。事實上,我看着她的代碼,發現了我不知道的validate()函數 - http://shiny.rstudio.com/articles/validation.html 但是,它似乎並不適用於ggvis – RInatM 2014-09-25 08:24:09