6

私の ggvis プロットは、入力データのフィルターのように機能するいくつかの入力フィールドに依存しています。組み合わせによっては、結果のデータ フレームが空になり、ggvis がエラーをスローしてアプリケーション全体を壊します。入れてみました

if(nrow(inputdataframe) == 0) return NULL 
if(nrow(inputdataframe) == 0) return ggvis()

これは役に立ちませんでした。この状況で適切な戻りパラメータは何ですか (代わりに空のプロットまたはテキスト メッセージが必要です)?

サーバー.R

effvis <- reactive ({
      dta <- siteeff()
      if(nrow(dta)  == 0) return(NULL)
      dta %>%
          ggvis(~param.value, ~yvar) %>%
          layer_points( size := 50, size.hover := 200) %>%
          set_options(width = 800, height = 500)
})
effvis %>% bind_shiny("effplot")

ui.R --

ggvisOutput("effplot")

アップデート

データが空のときにすべてのデータを表示したくありません (ここで提案されているように) 紛らわしいです

4

2 に答える 2

4

そのため、コード内のロジックをさらに確認すると役に立ちます。一般的に言って、リアクティブ式がプログラム ロジックのコンテキストでどのように機能するかを理解することは非常に重要です。光沢のあるホームページのコードをできるだけ多く読んでみたいと思います。これは、私が書いた簡単なスクリプトであり、あなたが求めているものになると思います。乾杯。

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")
       )
      )
     )
    )  
于 2014-09-25T17:00:49.373 に答える