Reading a csv from github (shiny app)

24 views
Skip to first unread message

Ahmad MM

unread,
Aug 22, 2017, 4:23:08 PM8/22/17
to Shiny - Web Framework for R
Hi all,


For the "Treatment Models" tab there should be a table but it is not displaying. It works locally but not when I publish it.

here is my code:

UI:

library(shiny)
library(shinydashboard)
library(RCurl) #package for the get URL function 
library(foreign)
library(httr) # to embed HTML documents in Shiny


dashboardPage(skin = "purple",      
              dashboardHeader(title= "CAMH NDS-STOP"), #Insert the Main Title
                             # titleWidth = 350), #Longer Title Width
              
              dashboardSidebar(  
                sidebarMenu(
                  menuItem("Objective", tabName= "first", icon= icon("info-circle")),
                  menuItem("History", tabName="second", icon=icon("clock-o")),
                  menuItem("Treatment Models", tabName = "third", icon=icon("user-md")),
                  menuItem("References/Resources", tabName="last", icon=icon("book"))
                          )),
              
              dashboardBody(  
                tabItems(
                  tabItem(tabName= "first",
                          htmlOutput("includeHTML")
                          ),
                  tabItem(tabName="second",
                          img(src="History_STOP.jpg") 
                          ),
                  tabItem(tabName="third",
                          h4("Since 2005, the program has investigated 15 models of distributing free cessation medication in combination with various degrees of counseling support to elligible smokers- 13 with Nicotine Replacement Therapy (NRT), & 2 with prescription medications (bupropion & varenicline)."),
                          DT::dataTableOutput("Table1"))
                  ))
            )

Server:

library(shiny)
library(shinydashboard)
library(RCurl) #package for the get URL function 
library(foreign)
library(httr) # to embed HTML documents in Shiny


#HTML: Objective
Objective.html<- content(request, as="text")


#Table: Treatment Models of STOP
Treatment_Models<-read.csv (text=getURL("https://raw.githubusercontent.com/AhmadMobin/STOP/master/Understanding_STOP/Tables/Treament_models.csv"),header = TRUE, stringsAsFactors = FALSE, fileEncoding = "UTF-8")
#Renaming column
names(Treatment_Models)[1]<- "Study Arm"
names(Treatment_Models)[2]<- "Provider Type"
names(Treatment_Models)[3]<- "Treatment Intervention"


shinyServer(function(input, output) {  
  

#OBJECTIVE HTML 
output$includeHTML <- renderText({Objective.html})

#TREATMENT MODELS TABLE
output$Table1 <- DT::renderDataTable({
  DT::datatable(options = list(paging = FALSE, searching= TRUE, 
                               autoWidth = TRUE, ordering=FALSE,
                               columnDefs = list(list(width = '800px', targets = "_all"))),
                Treatment_Models[,]  
  )  
})


})    

Ahmad MM

unread,
Aug 22, 2017, 4:40:41 PM8/22/17
to Shiny - Web Framework for R
I have determined that the html file under the "Objective" tab is somehow masking the table I have under the "Treatment Model" tab.

Here is the code:

#HTML: Objective
Objective.html<- content(request, as="text")

If I take this away the table will show up...

any thoughts?

Joe Cheng [RStudio]

unread,
Aug 22, 2017, 8:19:00 PM8/22/17
to Shiny - Web Framework for R
You're injecting a full HTML page (Objective.html), which includes a lot of JS dependencies, into your Shiny app's JS page. It's likely these dependencies are conflicting. I would recommend you load Objective.html via an <iframe> instead of just inlining it. Since GitHub doesn't serve up HTML files with the appropriate content types, you will have to use a URL from e.g. http://rawgit.com/ instead.

Ahmad MM

unread,
Aug 23, 2017, 10:28:29 AM8/23/17
to Shiny - Web Framework for R
Thanks Joe!

Here is my app. The html displays now. I was wondering how I can increase the height to extend to the full page?

UI

dashboardPage(skin = "purple",      
              dashboardHeader(title= "CAMH NDS-STOP"), #Insert the Main Title
                             # titleWidth = 350), #Longer Title Width
              
              dashboardSidebar(  
                sidebarMenu(
                  menuItem("Objective", tabName= "first", icon= icon("info-circle")),
                  menuItem("History", tabName="second", icon=icon("clock-o")),
                  menuItem("Treatment Models", tabName = "third", icon=icon("user-md")),
                  menuItem("References/Resources", tabName="last", icon=icon("book"))
                          )),
              
              dashboardBody(  
                tabItems(
                  tabItem(tabName= "first",
                          htmlOutput("frame")
                          ),
                  tabItem(tabName="second",
                          img(src="History_STOP.jpg") 
                          ),
                  tabItem(tabName="third",
                          h4("Since 2005, the program has investigated 15 models of distributing free cessation medication in combination with various degrees of counseling support to elligible smokers- 13 with Nicotine Replacement Therapy (NRT), & 2 with prescription medications (bupropion & varenicline)."),
                          DT::dataTableOutput("Table1"))
                  ))
            )

SERVER:
library(shiny)
library(shinydashboard)
library(RCurl) #package for the get URL function 
library(foreign)
library(httr) # to embed HTML documents in Shiny


shinyServer(function(input, output) {  
  

#OBJECTIVE HTML 
output$frame <- renderUI({

tags$iframe(src="https://cdn.rawgit.com/AhmadMobin/STOP/master/Understanding_STOP/www/Objective.html", seamless=NA, scrolling="yes",width = "100%", height="100%")
})

#TREATMENT MODELS TABLE
output$Table1 <- DT::renderDataTable({
  DT::datatable(options = list(paging = FALSE, searching= TRUE, 
                               autoWidth = TRUE, ordering=FALSE,
                               columnDefs = list(list(width = '800px', targets = "_all"))),
                Treatment_Models[,]  
  )  
})


})    

Ahmad MM

unread,
Aug 23, 2017, 10:49:07 AM8/23/17
to Shiny - Web Framework for R
NEVERMIND.

I made the following adjustment in the SERVER.R and all is good now! Thanks so much Joe!

output$frame <- renderUI({

tags$iframe(src="https://cdn.rawgit.com/AhmadMobin/STOP/master/Understanding_STOP/www/Objective.html", seamless="yes", scrolling="yes",width = "100%", height=700)
})
Reply all
Reply to author
Forward
0 new messages