library(shiny)
library(DT)
library(treemap)
library(d3treeR)
library(dplyr)
library(parsetR)
library(htmlwidgets)
shinyServer(function(input, output) {
groupData <- eventReactive(input$actionButton,{
group <-
structure(
list(
location = structure(
c(
1L, 1L, 1L, 2L, 2L, 3L,
3L, 4L, 5L, 5L, 6L, 6L, 7L, 8L, 8L, 8L, 9L, 9L, 9L, 10L, 10L,
11L, 11L, 11L, 11L, 12L, 12L, 13L, 13L, 13L, 13L, 14L, 14L, 15L,
16L, 16L, 16L, 16L, 17L, 17L, 17L, 18L, 18L, 18L, 18L
), .Label = c(
"ATC",
"CN-DAINAM", "CN-GIALAI", "CN-LIENDANH", "CN-LONGAN", "CN-NGHEAN",
"DC-BACGIANG", "DC-BENTRE", "DC-CONGTHANH", "DC-DAINAM", "DC-DATLOC",
"DC-HAIDUONG", "DC-HUNGYEN", "DC-SSMOI", "DC-THIENNAM", "HN-BRANCH",
"HP-BRANCH", "SM-THAIBINH"
), class = "factor"
), level = structure(
c(
1L,
2L, 3L, 1L, 2L, 1L, 2L, 6L, 1L, 2L, 1L, 2L, 2L, 1L, 2L, 3L, 1L,
2L, 3L, 1L, 2L, 1L, 2L, 3L, 4L, 1L, 2L, 1L, 2L, 3L, 4L, 1L, 2L,
1L, 1L, 2L, 3L, 6L, 1L, 2L, 3L, 3L, 4L, 5L, 6L
), .Label = c("1",
"2", "3", "4", "5", "6"), class = "factor"
), amount = c(
13L,
62L, 20L, 29L, 81L, 3L, 10L, 1L, 1L, 2L, 1L, 2L, 1L, 1L, 9L,
2L, 10L, 3L, 2L, 21L, 27L, 26L, 355L, 7L, 1L, 6L, 11L, 4L, 5L,
6L, 3L, 8L, 34L, 1L, 44L, 135L, 1L, 2L, 13L, 9L, 2L, 5L, 5L,
4L, 4L
)
), class = "data.frame", row.names = c(NA,-45L), .Names = c("location",
"level", "amount")
)
return(group)
})
output$dataTable <- DT::renderDataTable(
datatable(
groupData(),filter = "top", rownames = FALSE,
extensions = 'ColVis',
options = list(
dom = 'C<"clear">lfrtip', autoWidth = TRUE,
lengthMenu = list(c(50, 100,-1), c('50', '100','All'))
)
) %>%
formatStyle(c('level'),
backgroundColor = styleInterval(
c(1,2,3,4,5,6),
c('brown','red',"lime","pink",
"yellow","cyan", "purple")
))
)
output$d3Tree <- renderD3tree2(d3tree2(
treemap(
groupData(),
index = c("location", "level"),
vSize = "amount",
vColor = "amount",
type = "value"
)
,rootname = "lohoi"
))
output$parset <- renderParset(parset(
as.data.frame(groupData()), dimensions = c("level", "location"),
value = htmlwidgets::JS("function(d){return d.amount}"),
tension = 0.5
))
})
The app runs fine on RStudio.
Listening on http://127.0.0.1:53770
Attaching package: ‘DT’
The following objects are masked from ‘package:shiny’:
dataTableOutput, renderDataTable
Note: the specification for S3 class “AsIs” in package ‘jsonlite’ seems equivalent to one from package ‘RJSONIO’: not turning on duplicate class definitions for this class.
Loading required package: vcdExtra
Loading required package: vcd
Loading required package: grid
Loading required package: gnm
Attaching package: ‘dplyr’
The following object is masked from ‘package:vcdExtra’:
summarise
The following objects are masked from ‘package:stats’:
filter, lag
The following objects are masked from ‘package:base’:
intersect, setdiff, setequal, union
Error in (function (file = ifelse(onefile, "Rplots.pdf", "Rplot%03d.pdf"), :
cannot open file 'Rplots.pdf'
Therefore, the tab which contains d3tree2Output could not render the plot with message:
The others tabs (DT and parsetR) were rendered correctly (though parsetR had problem stated here: timelyportfolio/parsetR#2)
R on the server is 3.2.1, all the packages using in the example are up to date.
Please let me know how to fix it.