I'm trying to include a shiny implementation in a package I'm making. I see that in shiny::runApp()
you can specify the UI and server as a list rather than a directory location:
runApp(list(
ui = bootstrapPage(
numericInput('n', 'Number of obs', 100),
plotOutput('plot')
),
server = function(input, output) {
output$plot <- renderPlot({ hist(runif(input$n)) })
}
))
How do you do this when using a custom HTML UI? And where should the relevant files be placed in a package's directory? The layout of the shiny application would look something like this:
server.R
www/
style.css
scripts.js
I think the solution might involve includeHTML()
, includeCSS()
etc., but I can't figure out what the documentation is saying.
Yes! A shiny app can be put in an iframe in another website from RStudio Connect. In order to put the app in an iframe, it is recommended to add a content URL, because you can move it to another piece of content should the need arise.
You cannot put raw HTML directly into a tag or UI object. Shiny will treat raw HTML as a character string, adding HTML as text to your UI document. To add raw HTML, use the HTML function. HTML takes a character string and returns it as HTML (a special class of object in Shiny).
You package hierarchy should look like this :
R
launcher.R
man
inst
myshinyapp
server.R
www
index.html ## here your ui interface
shared
js
yourscript.js
css
style.css
in launcher.R should add this function:
runUI <- function ()
shiny::runApp(
system.file('myshinyapp',
package='my_package_name')) ## your package name here
You should export/import in NAMESPACE:
export(runUI)
import(shiny)
and in DESCRIPTION imports sections:
Imports:shiny
Well, you can achieve this by putting all your HTML inside the HTML() function. Make sure you pass valid HTML for Shiny then you should be fine!
runApp(list(
ui = bootstrapPage(
HTML("<h1>Hello World</h1>")
),
server = function(input, output) {
output$plot <- renderPlot({ hist(runif(input$n)) })
}
))
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