title: input string 1 is invalid UTF-8 Shiny app
body: <p>I am trying to create a shiny app and keep gettint the error <code>Warning: Error in sub: input string 1 is invalid UTF-8</code> that prevents my <code>selectInput</code> from showing up.  I have tried using the <code>utf8</code> package to convert the strings to valid UTF-8 strings and have even tested before running the app to confirm they are all UTF-8 valid <code>mean(utf8_valid(unique(lol_data$name)))[1] 1</code> and yet the error still occurs.  Any help on getting this to work would be much appreciated.</p>
  <p><strong>Code For Shiny App</strong>
  This is the code for my app.</p>
  <pre><code>setwd(&quot;&quot;)
  library(shiny)
  lol_data &lt;- read_csv(paste(&quot;data/shiny/cleanedlol_data&quot;, 
                             Sys.Date(), sep = ''))
  
  # Define UI for application that draws a histogram
  ui &lt;- fluidPage(
    titlePanel(&quot;How well will your lol draft do?&quot;),
    sidebarLayout(
     sidebarPanel(
       selectInput(
         &quot;player&quot;,
         &quot;select your player *required&quot;,
         choices = unique(as.character(lol_data$name))
       ),
       uiOutput(&quot;secondSelection&quot;),
       uiOutput(&quot;thirdSelection&quot;),
       uiOutput(&quot;fourthSelection&quot;),
       uiOutput(&quot;fifthSelection&quot;)
     ),
     mainPanel(
       plotOutput(&quot;histogram&quot;)
     )
    )
  )
  
  # Define server logic required to draw a histogram
  server &lt;- function(input, output) {
    output$secondSelection &lt;- renderUI({
      selectInput(&quot;opp_name&quot;, &quot;select your opponent&quot;, 
                  choices = unique(lol_data %&gt;%
                                           filter(name == input$player &amp;
                                                    ifelse(!is.na(input$team),
                                                           lol_data$team ==
                                                             input$team,
                                                           !is.na(lol_data$team)) &amp;
                                                    ifelse(!is.na(input$team_vs),
                                                            lol_data$team_vs ==
                                                              input$team_vs, 
                                                            !is.na(team_vs)) &amp;
                                                    ifelse(!is.na(input$role),
                                                           lol_data$role ==
                                                             input$role,
                                                           !is.na(lol_data$role))
                                                           )) %&gt;%
                                         pull(opp_name))
    })
    output$thirdSelection &lt;- renderUI({
      selectInput(&quot;team&quot;, &quot;select your player's team&quot;, 
                  choices = unique(lol_data%&gt;%
                                           filter(name == input$player &amp;
                                                    ifelse(!is.na(input$opp_name),
                                                           lol_data$opp_name ==
                                                             input$opp_name,
                                                           !is.na(lol_data$opp_name)) &amp;
                                                           ifelse(!is.na(input$team_vs),
                                                                  lol_data$team_vs ==
                                                                    input$team_vs, 
                                                                  !is.na(team_vs)) &amp;
                                                           ifelse(!is.na(input$role),
                                                                  lol_data$role ==
                                                                    input$role,
                                                                  !is.na(lol_data$role))
                                                    )) %&gt;%
                    pull(team))
    })
    output$fourthSelection &lt;- renderUI({
      selectInput(&quot;team_vs&quot;, &quot;select your opposing team&quot;, 
                  choices = unique(lol_data%&gt;%
                                           filter(name == input$player&amp;
                                                    ifelse(!is.na(input$opp_name),
                                                           lol_data$opp_name ==
                                                             input$opp_name,
                                                           !is.na(lol_data$opp_name) &amp;
                                                           ifelse(!is.na(input$team),
                                                                  lol_data$team ==
                                                                    input$team, 
                                                                  !is.na(team)) &amp;
                                                           ifelse(!is.na(input$role),
                                                                  lol_data$role ==
                                                                    input$role,
                                                                  !is.na(lol_data$role))
                                                    )) %&gt;%
                                           pull(team_vs)))
    })
    output$fifthSelection &lt;- renderUI({
      selectInput(&quot;role&quot;, &quot;select your player's role&quot;, 
                  choices = unique(lol_data%&gt;%
                                           filter(name == input$player &amp;
                                                    ifelse(!is.na(input$team),
                                                           lol_data$team ==
                                                             input$team,
                                                           !is.na(lol_data$team)) &amp;
                                                           ifelse(!is.na(input$team_vs),
                                                                  lol_data$team_vs ==
                                                                    input$team_vs, 
                                                                  !is.na(team_vs)) &amp;
                                                           ifelse(!is.na(input$opp_name),
                                                                  lol_data$opp_name ==
                                                                    input$opp_name,
                                                                  !is.na(lol_data$opp_name))
                                                    )) %&gt;%
                    pull(role))
    })
    output$hist &lt;- renderPlot({
      data_name &lt;- subset(lol_data, name == input$player, opp_name = input$opp_name,
                          team == input$team, team_vs == input$team_vs,
                          role == input$role)
      ggplot(data_name, aes(x = points))+
        geom_histogram()
    })  
  }
  
  
  shinyApp(ui = ui, server = server)
  </code></pre>
  <p><em><strong>Result</strong></em>
  This is the result I get when I test the App.</p>
  <pre><code>runApp('~/test')
  Warning: Missing column names filled in: 'X1' [1]
  Parsed with column specification:
  cols(
    .default = col_double(),
    name = col_character(),
    link = col_character(),
    champion = col_character(),
    summoner_spells = col_character(),
    items = col_character(),
    team = col_character(),
    team_vs = col_character(),
    player_win = col_character(),
    date_time_utc = col_datetime(format = &quot;&quot;),
    role = col_character(),
    unique_line = col_character(),
    unique_game = col_character(),
    unique_line_vs = col_character(),
    current_year = col_logical(),
    opp_name = col_character(),
    opp_team = col_character(),
    opp_team_vs = col_character(),
    opp_player_win = col_character(),
    opp_date_time_utc = col_datetime(format = &quot;&quot;),
    opp_role = col_character()
    # ... with 1 more columns
  )
  See spec(...) for full column specifications.
  |=================================================================================================================| 100%  416 MB
  
  Listening on http://127.0.0.1:6931
  Warning: Error in sub: input string 1 is invalid UTF-8
    [No stack trace available]
  </code></pre>
  <p><em><strong>Code for preparing csv file pulled for app</strong></em>
  This is the relevant code for prepping the data that gives me the error.</p>
  <pre><code>library(utf8)
  if(str_detect(list.files(&quot;data/shiny/&quot;), 
                paste(&quot;cleanedlol_data&quot;, Sys.Date(),  sep = &quot;&quot;))){
    lol_data &lt;- read_csv(paste(&quot;data/shiny/cleanedlol_data&quot;, 
                               Sys.Date(), sep = ''))
  }else{
  
  lol_data &lt;- lol_data  %&gt;%
    janitor::clean_names() %&gt;%
    mutate(lg_kll_vr_sssts = replace(lg_kll_vr_sssts, 
                                     is.infinite(lg_kll_vr_sssts),NA),
           lg_kll_cs_vr_dth = replace(lg_kll_cs_vr_dth, 
                                      is.infinite(lg_kll_cs_vr_dth),NA),
           lg_kls_sts_cs_vr_dth = replace(lg_kls_sts_cs_vr_dth, 
                                          is.infinite(lg_kls_sts_cs_vr_dth),NA),
           lg_kls_vr_sts_cs = replace(lg_kls_vr_sts_cs, 
                                      is.infinite(lg_kls_vr_sts_cs),NA),
           lg_kl_vr_sts_cs_dth = replace(lg_kl_vr_sts_cs_dth, 
                                         is.infinite(lg_kl_vr_sts_cs_dth),NA),
           hist_points = points) %&gt;%
    arrange(name, date_time_utc) %&gt;%
    group_by(name) %&gt;%
    mutate(avg_points = mean(points, na.rm = TRUE)) %&gt;%
    mutate_at(c(&quot;kills&quot;, &quot;deaths&quot;, &quot;assists&quot;, &quot;gold&quot;, &quot;cs&quot;, &quot;team_kills&quot;,
                &quot;team_gold&quot;, &quot;hist_points&quot;, &quot;lg_kll_vr_sssts&quot;,
                &quot;lg_kll_cs_vr_dth&quot;, &quot;lg_kls_sts_cs_vr_dth&quot;, 
                &quot;lg_kls_vr_sts_cs&quot;, &quot;lg_kl_vr_sts_cs_dth&quot;), 
              list(~rollapply(lag(.), 3, 
                              mean, na.rm=T, 
                              partial = F,
                              fill = NA, 
                              align = &quot;right&quot;))) %&gt;%
    ungroup() %&gt;%
    group_by(name, current_year) %&gt;%
    mutate(current_yr_avg_pnts = mean(points, na.rm = TRUE),
           current_yr_avg_kills = mean(kills, na.rm = TRUE),
           current_yr_avg_deaths = mean(deaths, na.rm = TRUE),
           current_yr_avg_assists = mean(assists, na.rm = TRUE),
           current_yr_avg_gold = mean(gold, na.rm = TRUE),
           current_yr_avg_cs = mean(cs, na.rm = TRUE),
           crrnt_yr_avg_lg_kll_vr_sssts = mean(lg_kll_vr_sssts, na.rm = T),
           crnt_yr_avg_lg_kll_cs_vr_dth = mean(lg_kll_cs_vr_dth, na.rm=T),
           crnt_yr_lg_kls_sts_cs_vr_dth = mean(lg_kls_sts_cs_vr_dth, 
                                               na.rm=T),
           crnt_yr_lg_kls_vr_sts_cs = mean(lg_kls_vr_sts_cs, na.rm=T)) %&gt;%
    ungroup() %&gt;%
    select(-trinket, -keystone_mastery, -keystone_rune, -time, -dst, 
           -tournament, -game_id_wiki, -game_id_riot, -time_precision,
           -date_time_utc_precision) %&gt;%
    mutate_if(is.character, as_utf8) %&gt;%
    filter(complete.cases(.))
  
  opp_data &lt;- lol_data %&gt;%
    select(name, kills, deaths, assists, gold, cs, team_kills, team_gold, team, 
           team_vs,  player_win, date_time_utc, role,
           role_number, side, unique_line, unique_line_vs, 
            points,
           hist_points, current_yr_avg_pnts, current_yr_avg_kills , 
           current_yr_avg_deaths ,current_yr_avg_assists , 
           current_yr_avg_gold , current_yr_avg_cs,
           crrnt_yr_avg_lg_kll_vr_sssts, lg_kll_vr_sssts,
           crnt_yr_avg_lg_kll_cs_vr_dth, lg_kll_cs_vr_dth) %&gt;%
    rename(opp_name = name, opp_kills = kills, opp_deaths = deaths, 
           opp_assists =  assists, opp_gold = gold, opp_cs = cs, 
           opp_team_kills = team_kills, opp_team_gold = team_gold, 
           opp_team = team, opp_team_vs = team_vs, 
           opp_player_win = player_win,opp_date_time_utc = date_time_utc, 
           opp_role = role,
           opp_role_number = role_number, opp_side = side, 
           opp_unique_line = unique_line, opp_unique_line_vs = unique_line_vs,
           opp_points = points, 
           opp_hist_points = hist_points, 
           opp_current_yr_avg_pnts = current_yr_avg_pnts, 
           opp_current_yr_avg_kills = current_yr_avg_kills, 
           opp_current_yr_avg_deaths = current_yr_avg_deaths,
           opp_current_yr_avg_assists = current_yr_avg_assists, 
           opp_current_yr_avg_gold = current_yr_avg_gold, 
           opp_current_yr_avg_cs = current_yr_avg_cs,
           opp_crrnt_yr_avg_lg_kll_vr_sssts = crrnt_yr_avg_lg_kll_vr_sssts,
           opp_lg_kll_vr_sssts = lg_kll_vr_sssts,
           opp_crnt_yr_avg_lg_kll_cs_vr_dth = crnt_yr_avg_lg_kll_cs_vr_dth,
           opp_lg_kll_cs_vr_dth = lg_kll_cs_vr_dth)
  
  lol_data &lt;- lol_data %&gt;%
    left_join(opp_data, by = c(&quot;unique_line&quot; = &quot;opp_unique_line_vs&quot;))%&gt;%
    filter(complete.cases(.))
  
  write.csv(lol_data, file = paste(&quot;data/shiny/cleanedlol_data&quot;, 
                                   Sys.Date(), 
                                    sep = &quot;&quot;))
  
  }
  beep(&quot;fanfare&quot;)
  </code></pre>