Hi nirgrahamuk, I did what you told me, and I am getting that function "select" and "%>$" are not found. I don´t know why, I have the dplyr library, I don´t know what else to do...
I show you my code, maybe you can help me please…
#R shiny
library(shiny)
library(ggplot2)
library(readr)
library(dplyr)
library(DT)
coronavirus_total_20 <- read.csv("coronavirus_total_20.csv")
#Ui
library(shiny)
ui <- fluidPage(
titlePanel(title = h4("Ranking of COVID-19 Rates", align = "center")),
sidebarLayout(
sidebarPanel(
selectInput("data", "1- Select the data you want to know:", choices = c("Rate_confirmed_per_habitant", "Rate_deaths_per_habitant"), selected = "Rate_confirmed_per_habitant" ),
br(),
sliderInput("number", "2- Select the number of countries you want to rank:", min=5, max=20, value=10),
),
mainPanel(
tabsetPanel(type="tab",
tabPanel("Summary", verbatimTextOutput("summary")),
tabPanel("Structure", verbatimTextOutput("str")),
tabPanel("Data", tableOutput("tab")),
tabPanel("Plot", textOutput("obs"), plotOutput("myplot")))
)
)
)
#Server
server <- function(input, output) {
output$obs <- renderText(
paste("You are representing the first", input$number, "countries classified by ", input$data )
)
output$summary <- renderPrint({
colm <- req(input$data)
select(coronavirus_total_20, Country.Region, !!sym(colm)
) %>% summary()
})
output$str <- renderPrint({
colm <- req(input$data)
select(coronavirus_total_20, Country.Region,!!sym(colm)
) %>% str()
})
output$tab <- renderTable({
colm <- sym(req(input$data))
df <- select(coronavirus_total_20,Country.Region,!!sym(colm))
df1 <- df %>% arrange(-!!colm)
})
output$myplot <- renderPlot({
dat <- sym(req(input$data))
df2 <- select(coronavirus_total_20,Country.Region,!!dat)
df3 <- df2 %>% arrange(-!!dat)
cor <- filter(df3,row_number() <= req(input$number))
graph <- ggplot(cor, aes(x = reorder(Country.Region, -!!dat), y = !!dat, fill=!!dat)) +
geom_col()
graph + geom_text( aes( label = (!!dat)), vjust = -0.3, size=4) + labs(x= "Countries") + theme(axis.text.x = element_text(angle = 90, hjust = 1))
})
}
shinyApp(ui, server)