闪亮-将JavaScript变量存储到mysql数据库 [英] Shiny - store javascript variable to mysql database

查看:107
本文介绍了闪亮-将JavaScript变量存储到mysql数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用闪亮的服务器.
我的应用程序有一个搜索框输入.根据该输入,输出为数据表,其中具有可点击的链接.
我的应用程序的 ui.r 包含一个JavaScript函数,该函数可在每次单击链接时设置变量的值.将该变量设为 clickedLink .现在,我想将此链接的值存储到mysql或任何其他数据库.该怎么办?

I am working with shiny server.
My application has a search box input. Based on that input, the output is a dataTable which has clickable links.
My application's ui.r contains a JavaScript function that sets the value of a variable whenever a link is clicked. Let the variable be clickedLink. Now I want to store this value of link to mysql or any other database. How to go about this?

我没有尝试过ajax和php.这个问题描述了我所做的事情:将json数据保存到json使用ajax PHP 的文件,但我猜php文件不能正常运行.请帮忙.

I have tried ajax , php with no use. What I did is described in this question: saving json data to json file using ajax PHP but I guess php files do not work with shiny. Please help.

编辑1

代码已添加到ui.R

code added to ui.R

  tags$script(HTML("
     function clickFunction(clickedLink){
        //alert(clickedLink);
        var cl = clickedLink;
        Shiny.onInputChange('clickedLink',cl);
     }
  "))

代码已添加到服务器.R

code added to server.R

observe({
    print(input$clickedLink)

  })

编辑2
仅供参考,链接的格式为

EDIT 2
Just for information , the links are of the form

<a onclick="clickFunction(this.href); " target="_blank" href="http://SOMETING.com">SOMETHING</a>

推荐答案

我假设一旦在R中获得变量,便知道如何保存该变量.否则,请使用RMySQL软件包并阅读其教程- https://github.com/rstats-db/RMySQL

I'm assuming you know how to save the variable once you get it in R. If not, use the RMySQL package and read their tutorial - https://github.com/rstats-db/RMySQL

因此,您的主要问题是将javascript变量放入R.为此,您可以使用Shiny.onInputChange.这里有一个简短的简单教程 https://ryouready.wordpress.com/2013/11/20/sending-data-from-client-to-server-and-back-using-shiny/

So your main problem is getting the javascript variable into R. For that you can use Shiny.onInputChange. There's a short easy tutorial here https://ryouready.wordpress.com/2013/11/20/sending-data-from-client-to-server-and-back-using-shiny/

基本上,在javascript中, Shiny.onInputChange("jsvar", clickedLink)然后可以将jsvar视为常规反应输入,因此在R中,您可以执行`observe({saveToDb(input $ jsvar)})(必须定义saveToDb)

Basically, in javascript you would have Shiny.onInputChange("jsvar", clickedLink) and then you can treat jsvar as a regular reactive input, so in R you can do `observe({ saveToDb(input$jsvar) }) (you'd have to define saveToDb)

这篇关于闪亮-将JavaScript变量存储到mysql数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆