teamalgoritma / community

A place to ask questions and participate in discussions
41 stars 4 forks source link

Error : argument 1 is not a vector #706

Closed mchen899 closed 1 year ago

mchen899 commented 1 year ago

UI tabItem(tabName = "page2",

Untuk select input

            fluidRow(
              box(width = 12,
                selectInput(inputId = "select_input",
                              label = "Choose Country",
                              choices = unique(world$Country)))

            ),

            # untuk 2 plot
            fluidRow(
              #untuk plot_line
              box(width = 12,
                  plotlyOutput(outputId = "world_line"))
            )
    ),

Server

untuk plot world_line

output$world_line <- renderPlotly({
  # Plot line
  world_line <- world %>% 
    pivot_longer(cols = c("Population_2023","Population_2022", "Population_2020", "Population_2015","Population_2010", "Population_2000", "Population_1990", "Population_1980", "Population_1970"), names_to = "year", values_to = "value")
  world_line <- world_line %>%
    mutate(year = str_sub(year, 12, -1),
           year = as.numeric(year),
           Country = as.factor(Country)) %>%

    filter (Country %in% "input$select_input") %>%
    arrange(year)

  # Nambah label
  world_line <- world_line %>%  
    mutate(label = glue("Year: {year}
                  Population: {value}"))

  # Plot Statis
  world_line <- ggplot(data = world_line,
                       aes(x = year,
                           y = value)) +
    geom_line(col ="navy") +
    geom_point(aes(text = label),size = 2) +
    labs(title = "Population Growth From 1970 - 2023",
         x = "Year",
         y = "Population") +
    theme_minimal() +
    theme(plot.title = element_text(hjust=0.5))

  # Plot Interaktif
  ggplotly(world_line, tooltip = "text")
})

Help me which code triggered the error? When I tried in R script, it can run

error : argument 1 is not a vector

mchen899 commented 1 year ago

World Population.zip

ramdhinafinita commented 1 year ago

Dear Pak @mchen899

Bisa dicoba untuk dibenarkan pada bagian-bagian dibawah ini pak.

error di server

  1. pada bagian filter yang dinamis seharusnya tidak menggunakan tanda "" -> contohnya seperti ini filter(Population_category %in% input$input_world) sama hal nya pada bagian filter untuk plot line
  2. pada ggplot di plot line -> ggplot(data = world_line, aes(x = year, y = value))

pada geom_line bisa ditambahkan parameter linewidth = 1 karena sudah tidak bisa pakai size lagi di ggplot2 terbaru, sama juga pada geom_point()

pada global

mchen899 commented 1 year ago

tq @ramdhinafinita . sudah bisa running.

ramdhinafinita commented 1 year ago

oke pak @mchen899. Seharusnya jangan di issues, dan seharusnya pertanyaannya dimasukkan kedalam discussion. Terimakasih

mchen899 commented 1 year ago

baik bu. harap maklum baru menggunakan github. :)