updateselectinput

时间:2018-09-05 10:34:45

标签: r shiny shiny-reactivity

我有2个selectInput列表,第二个通过Access数据库更新了第一个列表...当您在第二个选择中选择一个输入时,我试图打印有关您选择内容的简短摘要,然后再单击以打印所有相应的数据。我的代码没有打印描述,而是显示“ character(0)”,当我在控制台中编写相同的代码时,它正在起作用...我在查询下面放了一个可重现的示例。

    library(shiny)
    #library(quantmod)
    library(lubridate)
    library(plotly)
    library(ggplot2)
    library(RODBC)

    #channel<-odbcConnectAccess("H:\\Analyse Macro\\Base Macro live.mdb")
    #liste<-sqlQuery(channel,paste("Select * from Liste_source"))
    #liste<-as.character(liste$Table)
      liste<-data.frame(Nom=c("BCE","FED","Eurostat"),Table=c("BCE","FED","Eurostat"))




    # Define UI for application that draws a histogram
    #shinyUI(fluidPage(
    ui<-tagList(
         navbarPage(
              "Evolutions Economiques",
              tabPanel("Observation",
                       # Application title
                       titlePanel("Evolutions Economiques"),

                       # Sidebar with a slider input for number of bins
                       #sidebarLayout(
                       sidebarPanel(
                            h1("Selection des donnees"),
                            selectInput("Source","Source :",
                                        choices =liste),
                            selectInput("indic","Indicateur :",
                                        choices = NULL),
                            selectInput("pays","Pays :",
                                        choices = NULL),
                            selectInput("partenaire","Partenaire :",
                                        choices = NULL),
                            submitButton("Ajouter"),
                            hr(),
                            img(src="logo.png",height=80,width=200),
                            br(),
                            br(),
                            helpText("Application realisee pour l'exploration des donnees macroeconomiques")
                       ),

                       # Show a plot of the generated distribution
                       mainPanel(
                            column(6,wellPanel(
                                 "Description de la selection :",
                            verbatimTextOutput("summary")
                            )),
                            plotlyOutput("graph")
                       )
              ),

              tabPanel("Extraction",
                       sidebarPanel(

                            selectizeInput("Index","Indice",c("ok")),
                            textInput("Nom","Nom fichier"),
                            actionButton("save","Sauver"),
                            hr(),
                            img(src="logo.png",height=80,width=200),
                            br(),
                            br(),
                            helpText("Application realisee pour l'exploration des donnees macroeconomiques")
                       ),

                       mainPanel(
                            tabsetPanel(type="tabs",
                                        tabPanel("liste",tableOutput("source")))
                       )


              ))
    )


#****** server 
    library(shiny)
    library(anytime)
    library(plotly)
    library(ggplot2)
    library(dplyr)
    library(RODBC)
    library(ecb)


    #channel<-odbcConnectAccess("H:\\Analyse Macro\\Base Macro live.mdb")

    voila_source<-function(selection){
         x<-as.character(selection)
         #liste_donnee<-sqlQuery(channel,paste0("Select * from ",x))
         #liste_donnee<-as.character(liste_donnee$Indice)
if (selection=="BCE"){
         liste_donnee<-data.frame(Indice=c("Billet en circu","Piece en circu"),
                 Description=c("Nombre billet","Nombre Piece"),
                 Code=c("CA.ETG","CA.ETV"),
                 Unite=c("Thousands of euro","Thousands of euro"),
                 Frequence=c("Mothnly","Mothnly"),
                 Pays=c("UEM","UEM"))
}

if (selection=="FED"){
         liste_donnee<-data.frame(Indice=c("Billet en circu","Piece en circu"),
                 Description=c("Nombre billet","Nombre Piece"),
                 Code=c("CA.ETG","CA.ETV"),
                 Unite=c("Thousands of dollar","Thousands of dollar"),
                 Frequence=c("Mothnly","Mothnly"),
                 Pays=c("USA","USA"))
}
         liste_donnee
    }




    #df<- as.data.frame(get_data(df))
    #df$obstime<-convert_dates(df$obstime)

    # Define server logic required to draw a histogram
    shinyServer(function(input, output,session) {


         observeEvent(input$Source,{
              #x<-as.character(input$Source)
              #liste_donnee<-sqlQuery(channel,paste0("Select * from ",x))
              #liste_donnee<-as.character(liste_donnee$Indice)
              liste_donnee<-voila_source(input$Source)



              updateSelectInput(session,"indic",
                                choices = liste_donnee$Indice)

         })


        apercu<-reactive({
          df<-voila_source(input$Source)
          df<-filter(df,Indice==input$indic)


          apercu<-list()
          apercu[[1]]<-as.character(df$Frequence)
          apercu[[2]]<-as.character(df$Unite)
          apercu[[3]]<-as.character(df$Pays)
          apercu[[4]]<-as.character(df$Description)

          names(apercu)<-c("Frequence :","Unite :","Pays :","Description :")
          apercu
     })




     output$summary<-renderPrint({
          apercu()

     })


    })

如果有人知道我要去哪里...

0 个答案:

没有答案