I’m packaging a shiny app with R. I have five files
The ui.R
ui <-
div(
class = "navbar1",
navbarPage(
div(tags$b("Test"), style = "color:#dcaaaa"),
theme = "custom.css",
tabPanel("Plot",
sidebarLayout(
sidebarPanel(
radioButtons("plotType", "Plot type",
c("Scatter"="p", "Line"="l")
)
),
mainPanel(
plotOutput("plot")
)
)
),
tabPanel("Summary",
verbatimTextOutput("summary")
),
navbarMenu("More",
tabPanel("Table",
DT::dataTableOutput("table")
),
tabPanel("About",
fluidRow(
# column(6,
# includeMarkdown("about.md")
# ),
column(9,
img(class="img-polaroid",
src=paste0("http://upload.wikimedia.org/",
"wikipedia/commons/9/92/",
"1919_Ford_Model_T_Highboy_Coupe.jpg")),
tags$small(
"Source: Photographed at the Bay State Antique ",
"Automobile Club's July 10, 2005 show at the ",
"Endicott Estate in Dedham, MA by ",
a(href="http://commons.wikimedia.org/wiki/User:Sfoskett",
"User:Sfoskett")
)
)
)
)
)
)
)
The server.R
server <- function(input, output, session) {
output$plot <- renderPlot({
plot(cars, type=input$plotType)
})
output$summary <- renderPrint({
summary(cars)
})
output$table <- DT::renderDataTable({
DT::datatable(cars)
})
}
The launchApp.R
#' launches the test shiny app
#'
#' @export launchApp
#'
#' @return shiny application object
#'
#' @example \dontrun {launchApp()}
#'
#' @import shiny
#'
# wrapper for shiny::shinyApp()
launchApp <- function() {
shinyApp(ui, server)
}
The custom.css
.navbar1 .navbar{background-color: #2C6D26;}
.navbar1 .navbar-default .navbar-brand{color: white;}
.navbar1 .navbar-nav li a:hover, .navbar1 .navbar-nav > .active > a
{
color: #fff !important;
background-color:#2C6D26 !important;
background-image: #fff !important;
}
The objective is to package this app into MyPackage
. Following http://r-pkgs.had.co.nz/inst.html, I created a folder www
under inst
. I organized the files like:
| MyPackage/
| R
| ui.R
| server.R
| launchApp.R
| inst
| www
| imgName.jpg
| custom.css
The image is available on http://upload.wikimedia.org/wikipedia/commons/9/92/1919_Ford_Model_T_Highboy_Coupe.jpg -- to be renamed as imgName.jpg
Could get the package built. But cannot get the css and jpg files working in the package.
There is Including an image in a shiny app package. But still can’t figure it out.
What’s the best way to achieve this? Many thanks!