javascript - Saving JS Code into RCloud Asset Book and Calling it in Shiny
问题描述
How would you put in java script code in an asset book and call it in shiny code? having some trouble getting it to work. I need to find a way to get that in a asset book in RCloud, and be able to call it within Rcloud, without having to reference the code online
#Link to JS Code I am trying to save inside Rcloud
tinymce.cachefly.net/4.0/tinymce.min.js
# Call asset to provide JS Code
tinymce.fn.source <- rcloud.get.asset("tinymce.js", notebook=assetsNotebook) source(textConnection(tinymce.fn.source))
Side Text Panel Code
fluidRow(
singleton(tags$head(tags$script(src ="tinymce.fn.source"))),
column(12, offset = 0,
hr(),
h4('Side Panel Text'),
uiOutput("editor1"))),
解决方案
library(rcloud.shiny)
library(shiny)
ui <- shinyUI(
fluidPage(tags$head(tags$script(src='/notebook.R/6a4819a38814bdad910e837f0c4de702/tinymce.min.js')),
# Application title
fluidRow(
titlePanel('tinyMCE Modal Example'),
br(),
actionButton('modal', 'Modal Example', icon=icon('paper-plane-o'), class='btn-success', style='margin-left:15px;',`data-toggle`='modal', `data-target`='#modalExample'),
br(),br(),
tags$pre(htmlOutput('modalText')),
### Modal ###
tags$div(class='modal fade', id='modalExample', tabindex='-1', role='dialog',`aria-labelledby`='modalExample', `aria-hidden`='true',
tags$div(class='modal-dialog', role='document',
tags$div(class='modal-content',
tags$div(class='modal-header', tags$button(type='button', class='close', `data-dismiss`='modal', `aria-label`='Close', tags$span(`aria-hidden`='true', 'x')),tags$h4(class='modal-title', 'HTML Editor in a modal')),
tags$div(class='modal-body', tags$form(method='post', tags$textarea(id='modalEditor')),tags$script("tinymce.init({selector:'#modalEditor', theme: 'modern', height: 200});")),
tags$div(class='modal-footer',tags$button(type='button', class='btn btn-primary', `data-dismiss`='modal', onclick="Shiny.onInputChange('modalTextArea',tinyMCE.get('modalEditor').getContent());",'Close')))
)
)
)
)
)
server <- function(input, output, session) {
output$modalText <- renderUI({
req(input$modalTextArea)
HTML(enc2utf8(input$modalTextArea))
})
}
rcloud.shinyApp(ui=ui, server=server)
我将 JS 保存到我的桌面,然后使用 File Upload GUI 加载,勾选 Upload to notebook 框以创建 RCloud Asset:
单击 RCloud Asset 部分中的链接图标,您将看到加载为 notebook.R 静态资产的 JS 代码:
notebook.R 接口(Web 服务)允许您使用笔记本的相对路径调用静态资产……例如,您可以在其他笔记本中创建函数并使用该路径调用它们。
推荐阅读
- cookies - 我如何要求 StackOverflow 网站存储我对隐私的偏好?
- node.js - 如何最好地从 nodejs 网络响应中提取内容主体?
- arrays - 将 C 结构的 Swift 数组转换为 UnsafeMutablePointer
- javascript - 有没有办法在没有快照的情况下对 firebase 数据进行分页?
- python - Instascrape (InvalidArgumentException: 无效参数: 'url' 必须是字符串")
- wordpress - WP以编程方式添加到购物车并保存项目元
- python-2.7 - 版本之间的 Python / Tkinter grid_rowconfigure 问题
- javascript - 执行我的文件时出现的这个错误是什么?
- react-native - 比较更新 redux 状态前后的值
- c# - UnauthorizedAccessException:使用管道在 IIS 中托管 .net 核心 mvc 时拒绝访问路径