rCharts与Highcharts一起作为闪亮的应用程序
我有一个由三个文件组成的闪亮的应用程序。server.R、ui.R和用于启动应用程序的文件rCharts与Highcharts一起作为闪亮的应用程序,r,highcharts,shiny,rcharts,R,Highcharts,Shiny,Rcharts,我有一个由三个文件组成的闪亮的应用程序。server.R、ui.R和用于启动应用程序的文件 require(shiny) require(rCharts) runApp("shinyApp") 应用程序启动,但绘图不可见。它适用于普通的r图和polycharts,但在尝试了很多之后,我仍然没有成功使用rCharts(包括rHighcharts) 这是上次尝试的文件: 服务器.R: library(rCharts) shinyServer(function(input, output) {
require(shiny)
require(rCharts)
runApp("shinyApp")
应用程序启动,但绘图不可见。它适用于普通的r图和polycharts,但在尝试了很多之后,我仍然没有成功使用rCharts(包括rHighcharts)
这是上次尝试的文件:
服务器.R:
library(rCharts)
shinyServer(function(input, output) {
output$myChart <- renderChart({
h1 <- Highcharts$new()
h1$chart(type = "spline")
h1$series(data = c(1, 3, 2, 4, 5), dashStyle = "longdash")
h1$series(data = c(NA, 4, 1, 3, 4), dashStyle = "shortdot")
h1$legend(symbolWidth = 80)
return(h1)
})
})
我的假设是“showOutput”的第二个参数可能是错误的,但我没有发现任何东西。这很可能是因为
rcharts
是javascript
的事实,因为R
变量名和javascript
允许的变量名之间存在强烈的不兼容。特别是关于名称中的点
尝试在数据框
名称和任何字符
列上运行以下函数:
noDot <- function(x)
gsub("\\.", "_", gsub("^\\.", "", x) )
noDot有两种方法可以让它工作。第一种方法是在server.R
中添加h1$set(dom=“myChart”)
。这是必需的,以便server.R
和ui.R
就正确的图表进行通信。另一种选择是使用renderChart2
,它位于rCharts
的dev
分支中,它是renderChart
的升级版本,最终将取代它。为了每个人的利益,我附上了整个代码
require(rCharts)
require(shiny)
runApp(list(
ui = pageWithSidebar(
headerPanel("rCharts: Highcharts"),
sidebarPanel(selectInput(
inputId = "x",
label = "Choose X",
choices = c('SepalLength', 'SepalWidth', 'PetalLength', 'PetalWidth'),
selected = "SepalLength"
)),
mainPanel(showOutput("myChart", "Highcharts"))
),
server = function(input, output){
output$myChart <- renderChart2({
h1 <- Highcharts$new()
h1$chart(type = "spline")
h1$series(data = c(1, 3, 2, 4, 5), dashStyle = "longdash")
h1$series(data = c(NA, 4, 1, 3, 4), dashStyle = "shortdot")
h1$legend(symbolWidth = 80)
return(h1)
})
}
))
require(rCharts)
需要(有光泽)
runApp(列表(
ui=页面带边框(
headerPanel(“rCharts:Highcharts”),
侧边栏面板(选择输入)(
inputId=“x”,
label=“选择X”,
选项=c('separalength','separalwidth','petalalength','PetalWidth'),
selected=“separalength”
)),
主面板(显示输出(“myChart”、“Highcharts”))
),
服务器=功能(输入、输出){
输出$myChart
names(df) <- noDot(names(df))
# and
char.cols <- sapply(df, function(x) any(is(x)=="character"))
df[, char.cols] <- sapply(df[, char.cols], noDot)
# note that this has not been tested
require(rCharts)
require(shiny)
runApp(list(
ui = pageWithSidebar(
headerPanel("rCharts: Highcharts"),
sidebarPanel(selectInput(
inputId = "x",
label = "Choose X",
choices = c('SepalLength', 'SepalWidth', 'PetalLength', 'PetalWidth'),
selected = "SepalLength"
)),
mainPanel(showOutput("myChart", "Highcharts"))
),
server = function(input, output){
output$myChart <- renderChart2({
h1 <- Highcharts$new()
h1$chart(type = "spline")
h1$series(data = c(1, 3, 2, 4, 5), dashStyle = "longdash")
h1$series(data = c(NA, 4, 1, 3, 4), dashStyle = "shortdot")
h1$legend(symbolWidth = 80)
return(h1)
})
}
))