R shiny interactive graph app - Labels error

Hi Folks,

I have written the code below with the aim of creating an r shiny app that downloads a file and creates an interactive graphs of 15 currencies for which the user an select the currency to view. They can also adjust the date range. The data can be successfully downloaded and the columns changed from factors to numeric. Nas have also been changed from String values to NAs that r studio recognises (I think).

I am new to r shiny and unfortunately my code does not run. Could anyone suggest any adjustments to make, please?

# install.packages("shiny", "dplyr", "readr")
library(shiny)
#library(shinythemes)
library(dplyr)
library(readr)
getwd()
dir=getwd()
zipFile= "/eurofxref-hist.zip"
download.file("https://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist.zip?ca541d0975ee9990bcecda9bd5f686ca", paste0(dir,zipFile), mode="wb")
csvFile<-unzip(paste0(dir,zipFile))
data<-read.csv(paste0(dir,csvFile),header=TRUE, sep="," , na.strings=c("N/A")) #automatically puts it into csv
dataframe<-as.data.frame(data)
#select columns for graph: Date[1], US Dollar[2], Chinese Yuan [30], Japanese Yen [3], Indian Rupee[33],  British Pound [9], Czech Koruny CZK[6], Danish Krone Dkk[7], Hungarian Forint HUF[10], Polish Zloty PLN[14], Romanian Leu Ron[16].
dataframe2<-dataframe[,c(1,2,30,3,33,9,6,7,10,14,16)]
#rename these columns in the dataframe2
colnames(dataframe2)<-c("Date", "US Dollar", "Chinese Yuan", "Japanese Yen", "Indian Rupee", "British Pound", "Czech Koruny", "Danish Krone", "Hungarian Forint", "Polish Zloty", "Romanian Leu")
#replace NA string values with a proper "NA" value this was already attempted when the file was read in
dataframe2<-data.frame(lapply(dataframe2, function(x){gsub("N/A",NA, x)}))
#convert column format t numeric and date where applicable
columns=c(2:11)
dataframe2[columns]<-data.frame(lapply(dataframe[,columns], function(x) as.numeric(as.character(x)))) #This introduces NA values???
dataframe2$Date<-as.Date(as.character(dataframe2$Date, "%Y-%m-%d"))
col_names<-colnames(dataframe2) #create  vector of column names
print(col_names)
print(dataframe2)

######################################################################################


# Load data
#data is in dataframe2

# Define UI
ui <- fluidPage(titlePanel("Currency graph"),
                sidebarLayout(
                  sidebarPanel(
                    fileInput('dataframe2'),
                    selectInput(#inputId = "col_names"),
                      choices = unique(col_names))),
                  
dateRangeInput("dates",("Date range"),
start="1999-01-04",
end=as.character(Sys.Date()),
                  
mainPanel(plotOutput(outputId="lineplot,width="100px",height="3000px"))))))
            


#define server
server <- function(input, output) {
  

#subset
  selected_currency <- reactive({
    req(input$date)

  })
  

#scatterplot
  output$lineplot <- renderPlot({
    plot(x = selected_currency()$date, y = col_names, type = "l",
         xlab = "Date", ylab = "Currency index")
    
  })
  
 
}



shinyApp(ui = ui, server = server)

Step 1:

Change

mainPanel(plotOutput(outputId="lineplot,width="100px",height="3000px"))
   

to

mainPanel(plotOutput(outputId="lineplot",width="100px",height="3000px"))
   

You need to close your quotes!

1 Like

Thank you so much :slight_smile: