0

I am trying to buil an app in Shiny R for school. But it keeps giving this error, and I don't know where it is coming from... (actually any help with this is awesome, because I can't seem to render a fine table...) My code,including the dut function on my EuropeanCatnamesSorted dataframe, looks as follows:

library(shiny)
library(readr)
library(maps)
library(DT)

dput(EuropeanCatnamesSorted.csv) =
structure(list(Denmark = c("Mille", "Bella", "Nala", "Fie", "Perle", 
"Luna", "Luna", "Emil", "Molly", "Kat", "Anton", "Frida", "Sally", 
"Stella", "Rosa", "Lucky", "Ronja", "Fluffy", "Karla", "Felix", 
"Findus", "Simba", "Sofus", "Tiger", "Misser", "Pjuske", "Nimbus", 
"Pelle", "Coco", "Bølle", "Freja", "Tarzan", "Mikkel", "Bailey", 
"Max", "Hannibal", "Charlie", "Bamse"), Netherlands = c("Lizzy", 
"Belle", "Missy", "Nala", "Pascha", "Kiki", "Aisha", "Dewi", 
"Lola", "Noa", "Misty", "Bella", "Floor", "Daisy", "Doris", "Fleur", 
"Luna", "Floor", "Nora", "Abel", "Tom", "Felix", "Bert", "Hans", 
"Oscar", "DJ", "James", "Sjors", "Bram", "Harry", "Dirkje", "Floris", 
"Bob", "Willem", "Pieter", "Fred", "Joep", "Karel"), Germany = c("Adalia", 
"Adeline", "Agna", "Agneta", "Alda", "Alviria", "Amalia", "Amelina", 
"Angela", "Angelika", "Anja", "Anka", "Anke", "Anneslise", "Antje", 
"Astrid", "Ava", "Beatrisa", "Bernadette", "Adagny", "Adam", 
"Adler", "Albert", "Alexander", "Alfred", "Alois", "Alphonse", 
"Altbier", "Ancel", "Anton", "Armin", "Arno", "August", "Benno", 
"Bertram", "Bjorn", "Blaz", "Brant"), Italy = c("Donatella", 
"Adrina", "Torta", "Albina", "Farfalle", "Uffa", "Florentina", 
"Italia", "Olympia", "Stella", "Alba", "Ammiro", "Alda", "Amara", 
"Bambi", "Prima", "Bianca", "Zola", "Camilla", "Bacio", "Zitto", 
"Esatto", "Tenero", "Aldo", "Cosmo", "Pelo", "Sonno", "Augusto", 
"Badare", "Dante", "Mario", "Alberto", "Giovanni", "Fabian", 
"Drago", "Draco", "Mattone", "Leonardo"), Turkey = c("Boncuk", 
"Pati", "Mavis", "Mia", "Maya", "Luna", "Luna", "Ponçik", "Minnak", 
"Arya", "Mor Mir", "Smokey", "Hera", "Misha", "Mirnav", "Angela", 
"Lucy", "Lucky", "Alex", "Minnos", "Pamuk", "Kedi", "Duman", 
"Yok", "Mestan", "Sütlaç", "Apti", "Minos", "Karamel", "Seker", 
"Hâris", "Leo", "Tarçin", "Osman", "Tom", "Ares", "Minnos", "Marinems"
), Belgium = c("Kitty", "Luna", "Poes", "Filou", "Minoes", "Musti", 
"Tijger", "Lucky", "Billie", "Chanel", "Lilly", "Zorro", "Nina", 
"Lily", "Mila", "Fluffy", "Mini", "Misty", "Belle", "Simba", 
"Marie", "Felix", "Oscar", "Mimi", "Toulouse", "Billy", "Frosti", 
"Minou", "Tijgertje", "Max", "Milo", "Findus", "Moustach", "Garfield", 
"Diesel", "Mickey", "Boris", "Minoe"), Englang = c("Abigail ", 
"Beatrice", "Caitlin", "Charlotte", "Cordelia", "Daisy", "Eleanor ", 
"Elizabeth", "Elvie", "Emma", "Gemma", "Imogen", "Isla", "Isobel", 
"Jane", "Kiera", "Mary", "Noira", "Olivia ", "Aidan", "Alfred", 
"Baird", "Balfour", "Baron", "Benson", "Calder", "Charles ", 
"Chester", "Corbin", "Damien", "Darby", "Devlin", "Dolan", "Fairfax", 
"Finn", "Gallagher", "Gavin", "George"), Spain = c("Playa", "Corazón", 
"Niebla", "Biele", "Gata", "Osa", "Flor", "Selva", "Montaña", 
"Cascada", "Lluvia", "Nieve", "Angel", "Buena", "Hermosa", "Amor", 
"Aconcia", "Alegría", "Alta", "Esponjoso", "Cielo", "Gato", "Lión", 
"Tigre", "Cazador", "Oso", "Rio", "Segundo", "Pequeño", "Bueno", 
"Hermoso", "Amante", "Cerveza", "Allegro", "Valiente", "Dulce", 
"Leonor", "Lupe"), Ireland = c("Kira", "Erin", "Sheena", "Rosalyn", 
"Orla", "Lia", "Muriel", "Glenda", "Breana", "Cadie", "Shanna", 
"Sybil", "Brigid", "Ciara", "Deirdre", "Fiona", "Iona", "Meara", 
"Saoirse", "Flannery", "Conan", "Murphy", "Gallagher –", "Kieran", 
"Finnegan – fair", "Donovan –", "Aidan –", "Doyle –", "Finley", 
"Kirby –", "Cillian –", "Carney", "Shane –", "Ronan –", "Liam –", 
"Fionn –", "Rys –", "Cormac"), `United States` = c("\n    \n  \n  Female\n\n\n\n    Bianca\n  ", 
"\n    \n  \n  Female\n\n\n\n    Blanche\n  ", "\n    \n  \n  Female\n\n\n\n    Cat\n  ", 
"\n    \n  \n  Female\n\n\n\n    Delilah\n  ", "\n    \n  \n  Female\n\n\n\n    Feline\n  ", 
"\n    \n  \n  Female\n\n\n\n    Fiona\n  ", "\n    \n  \n  Female\n\n\n\n    Ginger\n  ", 
"\n    \n  \n  Female\n\n\n\n    Gucci\n  ", "\n    \n  \n  Female\n\n\n\n    Gypsy\n  ", 
"\n    \n  \n  Female\n\n\n\n    Jinx\n  ", "\n    \n  \n  Female\n\n\n\n    Katniss\n  ", 
"\n    \n  \n  Female\n\n\n\n    Kitty\n  ", "\n    \n  \n  Female\n\n\n\n    Lady\n  ", 
"\n    \n  \n  Female\n\n\n\n    Leonie\n  ", "\n    \n  \n  Female\n\n\n\n    Luna\n  ", 
"\n    \n  \n  Female\n\n\n\n    Maxine\n  ", "\n    \n  \n  Female\n\n\n\n    Mitzi\n  ", 
"\n    \n  \n  Female\n\n\n\n    Nala\n  ", "\n    \n  \n  Female\n\n\n\n    Pixie\n  ", 
"\n    \n  \n  Male\n\n\n\n    Drake\n  ", "\n    \n  \n  Male\n\n\n\n    Felix\n  ", 
"\n    \n  \n  Male\n\n\n\n    Fritz\n  ", "\n    \n  \n  Male\n\n\n\n    Garfield\n  ", 
"\n    \n  \n  Male\n\n\n\n    Harley\n  ", "\n    \n  \n  Male\n\n\n\n    Hunter\n  ", 
"\n    \n  \n  Male\n\n\n\n    Leo\n  ", "\n    \n  \n  Male\n\n\n\n    Lionel\n  ", 
"\n    \n  \n  Male\n\n\n\n    Loki\n  ", "\n    \n  \n  Male\n\n\n\n    Lucky\n  ", 
"\n    \n  \n  Male\n\n\n\n    Midnight\n  ", "\n    \n  \n  Male\n\n\n\n    Milo\n  ", 
"\n    \n  \n  Male\n\n\n\n    Morris\n  ", "\n    \n  \n  Male\n\n\n\n    Rex\n  ", 
"\n    \n  \n  Male\n\n\n\n    Salem\n  ", "\n    \n  \n  Male\n\n\n\n    Sam\n  ", 
"\n    \n  \n  Male\n\n\n\n    Shadow\n  ", "\n    \n  \n  Male\n\n\n\n    Simba\n  ", 
"\n    \n  \n  Male\n\n\n\n    Sylvester\n  "), Portugal = c("Nina", 
"Mel", "Mia", "Luna", "Luna", "Pretinha", "Nick", "Fred", "Princesa", 
"Lili", "Safira", "Belinha", "Maggie", "Bella", "Sisi", "Gambiça", 
"Cristal", "Amora", "Sofia", "Gato", "Tom", "Mimi", "Nino", "Marie", 
"Romeu", "Pandora", "Bob", "Gata", "Mingau", "Thor", "Lua", "Black", 
"Mingal", "Mimosa", "Nego", "Negão", "Neguinha", "Pipoca"), Switzerland = c("Stella", 
"Lilly", "Foxy", "Sheila", "Filou", "Sora", "Mia", "Lucky", "Perla", 
"Olive", "Tequila", "Candy", "Bali", "Isis", "Jakie", "Sira", 
"Arta", "Indira", "Macasito", "Mimi", "Cleo", "Noah", "Oscar", 
"Tommy", "Fripouille", "Timber", "Gandalf", "Chili", "Simba", 
"Hógolyó", "Pocholi", "Sammy", "Smoky", "Pippo", "Mo", "Truffles", 
"Milo", "Jimmy"), Sweden = c("Molly", "Zorro", "Selma", "Diva", 
"Lucifer", "Luna", "Luna", "Sally", "Maja", "Kajsa", "Sushi", 
"Sam", "Saraswati", "Hamdi", "Hikari", "Gullan", "Trixie", "Sussi", 
"Silver", "Sissi", "Tiger", "Nisse", "Sigge", "Findus", "Doris", 
"Sixten", "Molly", "Simba", "Missy", "Felix", "Alice", "Morris", 
"Zantai", "Charlie", "Gösta", "Bosse", "Kaktus", "Zimba")), row.names = c(NA, 
-38L), class = c("tbl_df", "tbl", "data.frame"))

mapEurope = map("world", fill = TRUE, plot = FALSE)

catnamesEurope<-read_csv("EuropeanCatnamesSorted.csv")

NL<-unique(catnamesEurope$Netherlands)
GE<-unique(catnamesEurope$Germany)
UK<-unique(catnamesEurope$Englang)
IR<-unique(catnamesEurope$Ireland)
BE<-unique(catnamesEurope$Belgium)
DN<-unique(catnamesEurope$Denmark)
IT<-unique(catnamesEurope$Italy)
SW<-unique(catnamesEurope$Sweden)
SP<-unique(catnamesEurope$Spain)
US<-unique(catnamesEurope$`United States`)
SWI<-unique(catnamesEurope$Switzerland)
PO<-unique(catnamesEurope$Portugal)
TU<-unique(catnamesEurope$Turkey)

ui <- fluidPage(

    titlePanel("Catnames per European country and the US"),

    sidebarLayout(
        sidebarPanel(
            selectInput("country", "Country:", 
                        choices=colnames(catnamesEurope)),
            hr(),
            helpText("Selecting the top 38 names per European country & the US.")
        ),
        actionButton("update", "Update View"),

        mainPanel(
            h4("Names per country"),
            verbatimTextOutput("names per country"),
            dataTableOutput("table")
        )
    )
)

And server:


    server <- function(input, output) {
        output$table <- renderDataTable(datatable({
        data <- mapEurope
        if (input$country != "Germany") {
            data <- data[data$mapEurope == input$country,]
        }
        if (input$country != "Netherland") {
            data <- data[data$mapEurope == input$country,]
        }
        if (input$country != "Italy") {
            data <- data[data$mapEurope == input$country,]
        }
        data
    }))

    }

bretauv
  • 7,756
  • 2
  • 20
  • 57
  • 1
    Hi. Can you please make your example [reproducible](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) (ideally with `dput`)?. We have no way of knowing what is in "EuropeanCatnamesSorted.csv" – Conor Neilson Mar 21 '20 at 13:45
  • Yess definitely! fairly new to this, but i'm gonna try! – carmen024_6 Mar 21 '20 at 14:00
  • 1
    @carmen024_6 Can you clarify what you want in your data table? It appears that you provided with `dput` a dataframe with names and columns of countries, called `data`. But in `server` you assign `data` with `mapEurope`, and here `data$mapEurope` won't work (there is no column `mapEurope` in this object also called `mapEurope`, which is of class `map` and not a data frame). You can however extract `names` from `mapEurope`. – Ben Mar 21 '20 at 15:05
  • I believe the error you mention is an error in the UI, not in server. – Stéphane Laurent Mar 21 '20 at 18:55

0 Answers0