2016-08-24 4 views
0

このコードを作成してください。私はチャートを2度描くことができません。 このシーケンスのテキストボックスの入力値を試してください。RシャイニーダイナミックUIでgooglevisグラフを2回レンダリングできません

  1. 1、2及び6
  2. 1,6及び2

実施例1について、それは一度だけグラフをプロットします。例2の場合は、2度しかプロットされません(異なるグラフなので) これは、ユーザーが何度も何度も働くようにするためのヒントです。

ui <- fluidPage( 
tagList(textInput(inputId = "textbox", label = NULL,value = ""),actionButton("go", "Go"),uiOutput("ui"))) 

server <- function(input, output) {  

observeEvent(input$go, { 
output$plot1 <- renderGvis({ 
    df <- data.frame(country=c("US", "GB", "BR"), 
        val1=c(10,33,44), 
        val2=c(23,122,342)) 

    Sys.sleep(0.3) 
    gvisBarChart(df, xvar="country", yvar=c("val1", "val2"), 
       options=list(isStacked=TRUE, height = 300, width = 400)) 

}) 

output$plot2 <- renderGvis({ 
    df <- data.frame(country=c("IND", "RUS", "BR"), 
        val1=c(10,3333,244), 
        val2=c(2344,122,342)) 

    Sys.sleep(0.3) 
    gvisBarChart(df, xvar="country", yvar=c("val1", "val2"), 
       options=list(isStacked=TRUE, height = 300, width = 400)) 
    }) 
     output$ui <- renderUI({ 

     if(isolate(as.numeric(input$textbox)) %in% c(1,2,3)){ 
      box(title = "ABC", width = 10, height = 550, htmlOutput("plot1",height = 500))  
     }else{ 
      box(title = "DEF", width = 4, height = 550, htmlOutput("plot2",height = 500))  

     } 


     }) 
    }) 
    } 

答えて

1

専門家の助けを借りて、なぜそれが起こったのか理解できました。問題は、どのチャートがレンダリングされているかを把握しようとしているhtmlです。ダイナミックUIを持っているときと、同じgooglevisチャートが呼び出されているときだけ、それは収穫されます。 何らかの理由で、どのチャートが参照されているのかわからないため、データが入力されません。私は確かにHTMLに精通していないと私の声明は決定的ではないかもしれません。 それにもかかわらず、チャートのレンダリング中にチャートIDを追加することによって機能します。

次のコードを貼り付けて、将来的に誰かに役立つことを期待してください。

server <- function(input, output) {  

observeEvent(input$go, { 
output$plot1 <- renderGvis({ 
df <- data.frame(country=c("US", "GB", "BR"), 
       val1=c(10,33,44), 
       val2=c(23,122,342)) 

Sys.sleep(0.3) 
gvisBarChart(df, xvar="country",chartid = "plot1", 
yvar=c("val1", "val2"), 
      options=list(isStacked=TRUE, height = 300, width = 400)) 

}) 

output$plot2 <- renderGvis({ 
df <- data.frame(country=c("IND", "RUS", "BR"), 
       val1=c(10,3333,244), 
       val2=c(2344,122,342)) 

Sys.sleep(0.3) 
gvisBarChart(df, xvar="country", chartid = "plot2", 
      yvar=c("val1", "val2"), 
      options=list(isStacked=TRUE, height = 300, width = 400)) 
}) 
    output$ui <- renderUI({ 

    if(isolate(as.numeric(input$textbox)) %in% c(1,2,3)){ 
     box(title = "ABC", width = 10, height = 550, htmlOutput("plot1",height = 500))  
    }else{ 
     box(title = "DEF", width = 4, height = 550, htmlOutput("plot2",height = 500))  

    } 


    }) 
}) 
} 

私はgooglevisグラフの問題を解決してきたが、私はまだリーフレットパッケージからマップと同じことを行う方法を見つけるのに苦労しています。どのポインタも大歓迎です。おかげさまで

関連する問題