score:17

Accepted answer

there are two ways to get this working. the first way is to add h1$set(dom = "mychart") in your server.r. this is required so that both server.r and ui.r are communicating about the correct chart. the alternative is to use renderchart2, which is in the dev branch of rcharts, that is a upgraded version of renderchart and will eventually replace it. i am attaching the entire code for everyone's benefit.

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)
    })
  }
))

score:2

this is most likely due to the fact that rcharts is javascript based on there are strong incompatibilities between r variable names and javascript allowed variable names. specifically with regards to dots . in names.

try running the following function on the data.frame names and any character columns:

nodot <- function(x)
   gsub("\\.", "_", gsub("^\\.", "", x) )

ie:

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

Related Query

More Query from same tag