I need to include a js library into my Shiny app. Currently I use includeHTML to include the script directly into html codes. e.g.
includeHTML('URL.js')
The browser will show "Not Found" when I try to browser the js file if I use tags$script, e.g.
http://127.0.0.1:7106/URL.js tags$script(src = 'URL.js')
Now I put URL.js in the same folder of ui.r and server.r.
Where I should store the URL.js file? Or are there other ways to include a js file?
Thanks for any suggestions.
Packages to load need to be declared at the start of the app. R file, at the server side of the app. R or alternatively at the modules file. At the modules, the libraries can be declared either outside of the fooUI and fooServer module functions or inside.
Your title asks about importing a data frame into shiny. That can be done by storing the data frame either as a binary file using the save() function or a csv file using write. csv() and having the shiny app read it in using load() for a binary file or read. csv() for a csv file.
The jQuery framework is natively included in shiny. jQuery is a fast, small, and feature-rich JavaScript library. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers.
What you need to do is:
www
folder in the same folder as server.R
and ui.R
www
folder.tags$head(tags$script(src="hoge.js"))
in UI.The folder looks like:
├── server.R ├── ui.R └── www └── hoge.js
The ui.R
is something like
library(shiny) shinyUI(pageWithSidebar( headerPanel("New Application"), sidebarPanel( sliderInput("obs", "Number of observations:", min = 1, max = 1000, value = 500) ), mainPanel( plotOutput("distPlot"), tags$head(tags$script(src="hoge.js")) ) ))
and server.R
library(shiny) shinyServer(function(input, output) { output$distPlot <- renderPlot({ dist <- rnorm(input$obs) hist(dist) }) })
Note that these are templates generated by Rstudio.
Now head
of html looks like:
<head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> ... snip ... <script src="shared/slider/js/jquery.slider.min.js"></script> <script src="hoge.js"></script> </head>
Another way is to use:
includeScript("mapManipulator.js"),
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With