2

I am trying to make a shinyapp that uses location and character data from a Google Sheet to generate a map.

library(shiny)
library(leaflet)
library(tidyverse)
library(googlesheets4)
library(shinyjs)

ORGANIZATION_SHEET_ID <- "###googlesheetsID###"

organization_data <- googlesheets4::read_sheet(ORGANIZATION_SHEET_ID,
    col_types = c(
      Name = "character",
      Needs_Met = "character", 
      Address = "character",
      Org_Structure = "character",
      Contact = "character",
      Submission_Date = "character",
      Lon = "numerical",       
      Lat = "numerical",
      Type = "character",
      Hours = "character"
  ) 

But it gives me this error:

    Error in `googlesheets4::read_sheet()`:
! `col_types` must have length 1, not length 10.
Run `rlang::last_trace()` to see where the error occurred.

Even though the headers in the Google Sheet match the column names.

2 Answers 2

3

From the googlesheets4::read_sheet's documentation:

... col_types gives control of column types, similar to how col_types works in readr and readxl. Note that currently there is only support for the “shortcode” style of column specification and we plan to align better with readr’s capabilities in a future release.

So, you need to use col_types = "ccccccnncc" (assuming you provided the columns in order).

Sign up to request clarification or add additional context in comments.

Comments

2

From ?googlesheets4::read_sheet argument col_types:

Column types. Either NULL to guess all from the spreadsheet or a string of readr-style shortcodes, with one character or code per column. If exactly one col_type is specified, it is recycled. See Column Specification for more.

This suggests you can do one of three things:

1. NULL to guess

This is the default behavior.

organization_data <- googlesheets4::read_sheet(
  ORGANIZATION_SHEET_ID, 
  col_types = NULL
)

2. Use Shortcodes

See the "Column Specification" section of the help for options.

organization_data <- googlesheets4::read_sheet(
  ORGANIZATION_SHEET_ID, 
  col_types = "ccccccnncc"
)

3. Recycle

Perhaps read everything as character and cast columns to other types later.

organization_data <- googlesheets4::read_sheet(
  ORGANIZATION_SHEET_ID, 
  col_types = "c"
) 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.