Create selectInput reactive - flexdashboard with Shiny of the Rmarkdown

I’m using shiney for the first time. I want to create a reactive widget containing the names of the cities of interest for my study. When selecting cities, the rendered graph must change.

This is my imported csv:

Data20 = read_delim("SAC55.csv", delim = ",")
tail(Data20)

   `DIAS `    `SANTOAMARO ` ` CACHOEIRA ` `CDA ` `SAUBARA `   SFC
  <date>             <dbl>         <dbl>  <dbl>      <dbl> <dbl>
1 2020-08-10           690           333    466         47   668
2 2020-08-11           695           335    470         47   676
3 2020-08-12           717           350    483         48   687
4 2020-08-13           719           356    500         48   701
5 2020-08-14           736           370    507         49   708
6 2020-08-15           763           377    527         49   713
colnames(Data20) <- gsub(" ","",colnames(Data20))

DIAS       SANTOAMARO CACHOEIRA   CDA SAUBARA   SFC
  <date>          <dbl>     <dbl> <dbl>   <dbl> <dbl>
1 2020-08-10        690       333   466      47   668
2 2020-08-11        695       335   470      47   676
3 2020-08-12        717       350   483      48   687
4 2020-08-13        719       356   500      48   701
5 2020-08-14        736       370   507      49   708
6 2020-08-15        763       377   527      49   713

that’s the way i’m trying to create a reactive selectImput

Data20 = read_delim("SAC55.csv", delim = ",")
colnames(Data20) <- gsub(" ","",colnames(Data20))
Data20$DIAS = as.Date(Data20$DIAS)

ui = shinyUI(fluidPage(
  sidebarLayout(
    sidebarPanel(
selectInput(inputId = "Cidades", 
              label = "Cidades",
             choices = c("Santo Amaro" = "SANTOAMARO", "Cachoeira" = "CACHOEIRA", "Cruz das Almas" = "CDA", "Saubara" = "SAUBARA", "SFC" = "SFC"), 
             selected = "SANTOAMARO")),

mainPanel(plotlyOutput("city")))

  ))

server = shinyServer(function(input, output) {

  II <- reactive({
    Data20[ , c("DIAS", input$Cidades)]
     })

output$city = renderPlotly({
   ggplotly(ggplot(data = II(), mapping = aes_string("DIAS", y = input$cidades),  group=1))+
  geom_line(size = 1, col="pink")+
  geom_point(size = 1, col="red" )+
  labs(x = "DIAS") + 
  labs(y = "CASOS")+
  scale_x_date(NULL, date_labels = "%d, %b", date_breaks = "3 days")+
  scale_y_continuous(limits = c(0, 800), breaks = c(0,10,20,40,60,80,100,120,140,180,160,200,220,240,260,280,300,320,340,360,380,400,420,440,460,480,500,520,540,560,580,600,620,640,660,680,700,720,740,760,780,800,900))+
  theme(plot.title = element_text(hjust = 0.5))+
  theme(text=element_text(family=" Arial ", size=9, face="bold"))+
  theme(axis.text.x = element_text(family="Arial", face="bold", size=10, angle=45)) 
 })
})
shinyApp(ui = ui,server = server)

Although the widget with the names of the cities appears, the graphics are formed.
there is the error:
Error in +: non-numeric argument to binary operator [No stack trace available]

non-numeric argument to binary operator
14.execCallbacks(timeoutSecs, all, loop$id)
13.run_now(timeoutMs/1000, all = FALSE)
12.service(timeout)
11.serviceApp()
10…stacktracefloor…(serviceApp())
9.withCallingHandlers(expr, error = doCaptureStack)
8.domain$wrapSync(expr)
7.promises::with_promise_domain(createStackTracePromiseDomain(), expr)
6.captureStackTraces({ while (!.globals$stopped) { …stacktracefloor…(serviceApp()) } …
5…stacktraceoff…(captureStackTraces({ while (!.globals$stopped) { …stacktracefloor…(serviceApp()) } …
4.runApp(x)
3.do.call(“runApp”, args)
2.print.shiny.appobj(x)
1.(function (x, …) UseMethod(“print”))(x)

I tried several ways to resolve this, to no avail. If anyone can help me I will be very grateful.

1 Like