I am making shiny app for football team data. I have created the following code. But Most of the time I get an error "'data' must be 2-dimensional (e.g. data frame or matrix)" . I searched on internet but count find why this error occurs.
As mentioned in the code, The table get display and when I select a team it displays the matches of that particular team.(only when I have "data" in the server part). The code gives me error when I write table1(which I actually want to display).
I also find problem making datatables using DT, IS there any other alternative?
library(shiny)
library(shinydashboard)
library(DT)
library(data.table)
library(stringr)
data <- readRDS('C:\\users\\UJJVAL\\Desktop\\european_soccer.rds');
hometeam<- c(data$home_team)
ui <-
dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
fluidRow(
box(
title = "League",
selectInput("league","selectleague", c(data$home_team, data$away_team),selected = NULL)
),
fluidRow(
DT::dataTableOutput("table"),
DT::dataTableOutput("table2")
)))
)
server <- function(input, output) {
output$table <-DT::renderDataTable(
DT::datatable({
#Filter the data based on selected team
if (input$league !="anything"){
data <- data[(data$home_team) == input$league,]
toString(input$league) #converet to string for displaying
freq_hometeam<- str_count(hometeam, c(input$league)) # count number of matches
numberofmatches<-freq_hometeam[freq_hometeam[1:25979]==1]
length(numberofmatches)
table1<- c(input$league, freq_hometeam) #prepare data for table.
output$table2 <- DT::renderDataTable(DT::datatable({table1}))
}
data
# Actually I want to display table1 data as a table but it pops error data must be two dimeentional metrix or data
}))
}
shinyApp(ui, server)