1

I would like to update one of my pickerInput

ui.R looks like:

library(shiny)
library(gtools)
library(data.table)
library(DT)
library(shinyWidgets)
library(plotly)
# the 'datT2' dataset.

datT2<-fread(paste0('./data/','31122018KRB.csv'),header=TRUE, sep=";",stringsAsFactors = FALSE , encoding="UTF-8")



##
fluidPage(
    sidebarLayout(

        # Sidebar panel for inputs ----
        sidebarPanel(

            fluidRow(
                column(10,
                       h3("Port"),
                       selectInput(inputId = 'date',
                                   label = 'Stichtag:',
                                   choices = sort(list.files('./data', full.names = FALSE,
                                                 recursive = FALSE))
                                   ),
                       ###  
                       selectInput("gesell",
                                   "company:",
                                   choices = c(
                                       sort(unique(as.character(datT2$Gesellschaftsname ))))),
                       # Konzernbezeichnung

                       pickerInput(
                           inputId = "konz",
                           label = "Emittent:",
                           choices = c(sort(unique(as.character(datT2$Konzernbezeichnung )))),     
                           selected = sort(unique(as.character(datT2$Konzernbezeichnung ))),    
                           options = list(`actions-box` = TRUE, 
                                          `selected-text-format` = paste0("count > ", length(unique(as.character(datT2$Konzernbezeichnung )))-1) ,
                                          `count-selected-text` = "Alle",liveSearch = TRUE, 
                                          liveSearchPlaceholder= TRUE),  
                           multiple = T
                       )
                )
            )
            ,width = 3),
        ###
        # Main panel for displaying outputs ----
        mainPanel( 
            tabsetPanel(type = "tabs",
                        tabPanel("Tabelle", DT::dataTableOutput("table")),
                        tabPanel("Glossar")
            )#,  

        )#End_of_mainPanel

    )
)

and my server.R

function(input, output,session) {


    #gesell<-renderText({reactiveValues(input$gesell)})

    ### read the data for the summary
    #read the data 
    dataSum <- reactive({
        infile <- input$date
        if (is.null(infile)){
            return(NULL)
        }
        dataS<-fread(paste0('./data/',infile),header=TRUE, sep=";")
        dataS[is.na(data)]<- 0


    })

    #read the data for GUI
    dataGui <- reactive({
        infile <- input$date
        if (is.null(infile)){
            return(NULL)
        }
        # upload (read) the file (data)
        dataGUI<-fread(paste0('./data/',infile),header=TRUE, sep=";", encoding="UTF-8")
        dataGui[is.na(data)]<- 0
        dataGUI
    #})

    observeEvent(input$date, {
        # 
        updatePickerInput(session = session, inputId = "konz",
                          choices = dataGui$Konzernbezeichnung)
    })
    })    
}

However, it dose not update the konz. What do I do wrong? The other important question is: Would it update input$konz in fact for the use in server.R or it shows just the update in ui.R? the first data set is: 31122018.csv

 Gesellschaftsname Konzernbezeichnung Rating
           UL                 LE     YB
           JX                 VU     OE
           RB                 AD     VZ
           XO                 KL     QG
           QN                 TP     XE
           IV                 UK     GD
           BV                 QB     WJ
           LZ                 UL     WR
           YY                 JC     UZ

and the second one 31122019.csv

Gesellschaftsname Konzernbezeichnung Rating
             UL                LEA     YB
             JX                VUA     OE
             RB               AAAD     VZ
             XO                 KL     QG
             QN                 TP     XE
             IV                 UK     GD
             BV                 QB     WJ
             LZ                 UL     WR
             YY                 JC     UZ
maniA
  • 1,437
  • 2
  • 21
  • 42
  • dataGui is a reactive so you would need to add brackets to your call to dataGui()$Konzernbezeichnung. But not sure if that’s the reason it’s not working. – TimTeaFan Jul 20 '19 at 22:14

1 Answers1

2

Regarding your first question. I am not able to reproduce your error with the code of my working example below. Maybe it helps you debugging your code.

Regarding your second question. input$konz is updated by selectPickerInput. This effects how input$konz is displayed in the UI as well as the values it carries in the server part. You can see that in the working example below the filter is working on the data no matter which dataset is selected - so the updated input$konz is not only cosmetic, but also changes the underlying values.

library("shiny")
library("tibble")
library("dplyr")
library("shinyWidgets")

# Generate data
data1 <- tribble(
    ~Gesellschaftsname, ~Konzernbezeichnung, ~Rating,
    "UL",                 "LE",     "YB",
    "JX",                 "VU",     "OE",
    "RB",                 "AD",     "VZ",
    "XO",                 "KL",     "QG",
    "QN",                 "TP",     "XE",
    "IV",                 "UK",     "GD",
    "BV",                 "QB",     "WJ",
    "LZ",                 "UL",     "WR",
    "YY",                 "JC",     "UZ"
)

data2 <- tribble(
    ~Gesellschaftsname, ~Konzernbezeichnung, ~Rating,
    "UL",                 "LEA",     "YB",
    "JX",                 "VUA",     "OE",
    "RB",                 "ADA",     "VZ",
    "XO",                 "KLA",     "QG",
    "QN",                 "TPA",     "XE",
    "IV",                 "UKA",     "GD",
    "BV",                 "QBA",     "WJ",
    "LZ",                 "ULA",     "WR",
    "YY",                 "JCA",     "UZ"
)



shinyApp(

    ui = fluidPage( # user interface

        sidebarLayout( # layout with Sidebar

            sidebarPanel( # input sidebarPanel

                # select data
                selectInput("data",
                            "Select data:",
                            choices = c("data1", "data2"),
                            selected = "data1"),



                # konz
                pickerInput(
                    inputId = "konz",
                    label = "Emittent:",
                    choices = c(sort(unique(as.character(data1$Konzernbezeichnung)))),     
                    selected = sort(unique(as.character(data1$Konzernbezeichnung))),    
                    options = list(`actions-box` = TRUE, 
                                   `selected-text-format` = paste0("count > ", length(unique(as.character(data1$Konzernbezeichnung )))-1) ,
                                   `count-selected-text` = "Alle",liveSearch = TRUE, 
                                   liveSearchPlaceholder = TRUE),  
                    multiple = T
                )



            ), # closes sidebarPanel

            mainPanel( # Output in mainPabel

                tableOutput("table")



            ) # closes mainPanel

        ) # closes sidebarLayout

    ), # closes fluidPage

    server = function(input, output, session) {

        reac_data_gui <- reactive({

            get(input$data)

        })

        reac_data <- reactive({

            reac_data_gui() %>% filter(Konzernbezeichnung %in% input$konz)

        })

        observeEvent(input$data, {

            updatePickerInput(session = session, inputId = "konz",
                              choices = sort(unique(as.character(reac_data_gui()$Konzernbezeichnung))),
                              selected = sort(unique(as.character(reac_data_gui()$Konzernbezeichnung))))
        })

        output$table <- renderTable({

            reac_data() 

        })

    }

)
TimTeaFan
  • 17,549
  • 4
  • 18
  • 39