2017-02-14 11 views
1

私はshinyappを持っています。他のオブジェクト/入力(他の操作を実行するボタンで、その結果は簡単には追跡できません。 )。だから私はボタンの入力を使わなければならなかった。すべてのボタンのコードを書き直すことなくメインオブジェクトを更新する方法はありますか?私の例では、私は2回をobserveEvent使用していた:光沢のあるオブジェクトいくつかの入力(ボタン)に対する反応性

library(datasets) 
library(shiny) 

ui<-fluidPage( 
    titlePanel("Telephones by region"), 
    sidebarLayout(  
    sidebarPanel(
     selectInput("region", "Region:", 
        choices=colnames(WorldPhones)), 
     helpText("Data from AT&T (1961) The World's Telephones."), 
     actionButton("submit", 
        label = "submit"), # this also has other functions 
     actionButton("change", 
        label = "change") # this also has other functions 
    ), 
    mainPanel(
     plotOutput("phonePlot") 
    ) 
) 
) 
server<-function(input, output) { 
data<-reactiveValues() 

observeEvent(input$submit,{ 
    data$data<-WorldPhones[,input$region] 
    }) 
observeEvent(input$change,{ 
    data$data<-WorldPhones[,input$region] 
}) 
output$phonePlot <- renderPlot({ 
    if(!is.null(data$data)) 
    barplot(data$data*1000, 
      ylab="Number of Telephones", 
      xlab="Year") 
    }) 
} 
shinyApp(ui = ui, server = server) 

答えて

0

あなたは単にc()を使用して、たとえば、両方のボタンを持つ式を行います。

observeEvent(c(input$submit,input$change),{ 
    data$data<-WorldPhones[,input$region] 
    }) 
関連する問題