Hi,
Something of a noob here but I've been tasked with adding a table of links to an existing Shiny app. Have created a stand-alone to play with until I get the table working and I just can't make it work - the problem comes with the loop I'm using to add rows to the table that include the clickable links. Using tag$ to create a HTML table because I couldn't find anything simpler that gave me clickable links.
Quick couple of notes on the dataset being referenced:
- I extracted an Excel sheet to the dataframe called fullData
- I have subsetted fullData into dataframes called employees, managers and both based on the EoM column in fullData (which has the value "Employee", "Manager" or "Both" in each row)
- I have ordered the employees, managers and both dataframes according to the value in Category
- The dataframes employees and managers have the same number of rows
- There is far fewer rows in the dataframe both
I have (or tried to) add some code to anticipate that many of the rows will have nothing for the both dataframe; when that happens I'm fine with a simple blank cell.
The problem seems to be with this loop; it gets me this error:
Error in parse(file, keep.source = FALSE, srcfile = src, encoding = enc) :I'd be thrilled if there's a pre-existing package I'm missing that creates me a formatted table which lets me do what I want, including the clickable links with alternative text, but I'd also happily take just turning what I've already got into something that works.
C:\Users\palme\OneDrive\Documents\HWA Dashboard Development/app.R:60:45: unexpected ','
59: } else {
60: tag$strong("both$Category[i]"),
^
Possible missing comma at:
47: for (i in 1:lengthEmployees){
^
Possible missing comma at: 47: for (i in 1:lengthEmployees){ ^
Error in sourceUTF8(fullpath, envir = new.env(parent = sharedEnv)) :
Error sourcing C:\Users\palme\AppData\Local\Temp\RtmpETti4P\file2cb0fa0739d
Full Code (have included line numbers because so many are referenced in the error - happy to repost without if that's causing more problems than it's solving):
1. library("readxl")
2. library("shiny")
3.
4. fullData <- read_excel("Links.xlsx")
5.
6. employees <- data.frame(fullData[fullData$EoM == "Employee", ])
7. managers <- data.frame(fullData[fullData$EoM == "Manager", ])
8. both <- data.frame(fullData[fullData$EoM == "Both", ])
9.
10. employees <- employees[order(employees$Category, decreasing = FALSE),]
11. managers <- managers[order(managers$Category, decreasing = FALSE),]
12. both <- managers[order(both$Category, decreasing = FALSE), ]
13.
14. lengthEmployees = nrow(employees)
15.
16. ui <- fluidPage(
17.
18. titlePanel("Testing"),
19.
20. sidebarPanel(),
21.
22. mainPanel(
23.
24. uiOutput("linksTable")
25.
26. )
27.
28. )
29.
30. server<- function(input, output){
31.
32. output$linksTable <- renderUI(
33. {
34. tags$table(
35. tag$tr(
36. tag$td(
37. tag$h3("Employee Guidance")
38. ),
39. tag$td(
40. tag$h3("Manager Guidance")
41. ),
42. tag$td(
43. tag$h3("Guidance for Both")
44. )
45. ),
46.
47. for (i in 1:lengthEmployees){
48. tags$tr(
49. tags$td(
50. tag$strong("employees$Category[i]"),
51. tag$a(href="employees$Link[i]", "employees$Text[i]")
52. ),
53 tag$td(
54. tag$strong("managers$Category[i]"),
55. tag$a(href="managers$Link[i]", "managers$Text[i]")
56. ),
57. if(is.null("both$Category[i]")){
58. tag$td()
59. } else {
60. tag$strong("both$Category[i]"),
61. tag$a(href="both$Link[i]", "both$Text[i]")
62. }
63. )
64. }
65.
66. )
67. }
68.
69. )
70.
71. }
72. shinyApp(ui,server)