As per object, I get a very small plot in Firefox when using sankeyNetwork() from networkd3 in shiny but not in Chrome or RStudio.
I have not included any CSS or JS in the script - the code below produces this result for me.
Is there any CSS property I have missed?
I am using R 3.4.1, shiny 1.1.0, networkD3 0.4 and Firefox 52.9.0.
Firefox:
Chrome:
library(shiny)
library(magrittr)
library(shinydashboard)
library(networkD3)
labels = as.character(1:9)
ui <- tagList(
dashboardPage(
dashboardHeader(
title = "appName"
),
##### dasboardSidebar #####
dashboardSidebar(
sidebarMenu(
id = "sidebar",
menuItem("plots",
tabName = "sPlots")
)
),
##### dashboardBody #####
dashboardBody(
tabItems(
##### tab #####
tabItem(
tabName = "sPlots",
tabsetPanel(
tabPanel(
"Sankey plot",
fluidRow(
box(title = "title",
solidHeader = TRUE, collapsible = TRUE, status = "primary",
sankeyNetworkOutput("sankeyHSM1")
)
)
)
)
)
)
)
)
)
server <- function(input, output, session) {
HSM = matrix(rep(c(10000, 700, 10000-700, 200, 500, 50, 20, 10, 2,40,10,10,10,10),4),ncol = 4)
sankeyHSMNetworkFun = function(x,ndx) {
nodes = data.frame("name" = factor(labels, levels = labels),
"group" = as.character(c(1,2,2,3,3,4,4,4,4)))
links = as.data.frame(matrix(byrow=T,ncol=3,c(
0, 1, NA,
0, 2, NA,
1, 3, NA,
1, 4, NA,
3, 5, NA,
3, 6, NA,
3, 7, NA,
3, 8, NA
)))
links[,3] = HSM[2:(nrow(links)+1),] %>% {rowSums(.[,(ndx-1)*2+c(1,2)])}
names(links) = c("source","target","value")
sankeyNetwork(Links = links, Nodes = nodes, Source = "source", Target = "target", Value = "value", NodeID = "name",NodeGroup = "group",
fontSize=12,sinksRight = FALSE)
}
output$sankeyHSM1 = renderSankeyNetwork({
sankeyHSMNetworkFun(values$HSM,1)
})
}
# Run the application
shinyApp(ui = ui, server = server)
------------------ EDIT --------------------
Thanks to #CJYetman for indicating onRender() as a possible solution - however this fails when there are two plots generated side by side as in the MRE below (note in addition to the second sankey plot I have also added javascript code to re-draw the figures when the window size changes as the plot does not appear to do it automatically).
library(shiny)
library(magrittr)
library(shinydashboard)
library(networkD3)
library(htmlwidgets)
labels = as.character(1:9)
ui <- tagList(
tags$head(
tags$script('
var dimension = [0, 0];
$(document).on("shiny:connected", function(e) {
dimension[0] = window.innerWidth;
dimension[1] = window.innerHeight;
Shiny.onInputChange("dimension", dimension);
});
$(window).resize(function(e) {
dimension[0] = window.innerWidth;
dimension[1] = window.innerHeight;
Shiny.onInputChange("dimension", dimension);
});
')
),
dashboardPage(
dashboardHeader(
title = "appName"
),
##### dasboardSidebar #####
dashboardSidebar(
sidebarMenu(
id = "sidebar",
menuItem("plots",
tabName = "sPlots")
)
),
##### dashboardBody #####
dashboardBody(
tabItems(
##### tab #####
tabItem(
tabName = "sPlots",
tabsetPanel(
tabPanel(
"Sankey plot",
fluidRow(
box(title = "title",
solidHeader = TRUE, collapsible = TRUE, status = "primary",
sankeyNetworkOutput("sankeyHSM1")
),
box(title = "plot2",
solidHeader = TRUE, collapsible = TRUE, status = "primary",
sankeyNetworkOutput("sankeyHSM2"))
)
)
)
)
)
)
)
)
server <- function(input, output, session) {
HSM = matrix(rep(c(10000, 700, 10000-700, 200, 500, 50, 20, 10, 2,40,10,10,10,10),4),ncol = 4)
sankeyHSMNetworkFun = function(x,ndx) {
nodes = data.frame("name" = factor(labels, levels = labels),
"group" = as.character(c(1,2,2,3,3,4,4,4,4)))
links = as.data.frame(matrix(byrow=T,ncol=3,c(
0, 1, NA,
0, 2, NA,
1, 3, NA,
1, 4, NA,
3, 5, NA,
3, 6, NA,
3, 7, NA,
3, 8, NA
)))
links[,3] = HSM[2:(nrow(links)+1),] %>% {rowSums(.[,(ndx-1)*2+c(1,2)])}
names(links) = c("source","target","value")
sankeyNetwork(Links = links, Nodes = nodes, Source = "source", Target = "target", Value = "value", NodeID = "name",NodeGroup = "group",
fontSize=12,sinksRight = FALSE)
}
output$sankeyHSM1 = renderSankeyNetwork({
req(input$dimension)
sankeyHSMNetworkFun(values$HSM,1) %>%
onRender('document.getElementsByTagName("svg")[0].setAttribute("viewBox", "")')
})
output$sankeyHSM2 = renderSankeyNetwork({
req(input$dimension)
sankeyHSMNetworkFun(values$HSM,2) %>%
onRender('document.getElementsByTagName("svg")[0].setAttribute("viewBox", "")')
})
}
# Run the application
shinyApp(ui = ui, server = server)
------------------ EDIT2 --------------------
Second problem above solved - either by referring to the second svg item on the page as per #CJYetman's comment below using document.getElementsByTagName("svg")[1].setAttribute("viewBox",""), or by going into the objects themselves selecting their first svg element with document.getElementById("sankeyHSM2").getElementsByTagName("svg")[0].setAttribute("viewBox","").
This seems to be the result of Firefox reacting to the viewbox svg property differently than other browsers. It might be worthwhile to submit this as an issue here https://github.com/christophergandrud/networkD3/issues
In the meantime, you could work around this by resetting the viewbox attribute using some JavaScript and htmlwidgets::onRender(). Here's an example using a minimized version of your example. (Resetting the viewbox attribute may have other consequences)
library(htmlwidgets)
library(networkD3)
library(magrittr)
nodes = data.frame("name" = factor(as.character(1:9)),
"group" = as.character(c(1,2,2,3,3,4,4,4,4)))
links = as.data.frame(matrix(byrow = T, ncol = 3, c(
0, 1, 1400,
0, 2, 18600,
1, 3, 400,
1, 4, 1000,
3, 5, 100,
3, 6, 40,
3, 7, 20,
3, 8, 4
)))
names(links) = c("source","target","value")
sn <- sankeyNetwork(Links = links, Nodes = nodes, Source = "source",
Target = "target", Value = "value", NodeID = "name",
NodeGroup = "group", fontSize = 12, sinksRight = FALSE)
htmlwidgets::onRender(sn, 'document.getElementsByTagName("svg")[0].setAttribute("viewBox", "")')
UPDATE (2019.10.26)
This is probably a safer implementation of removing the viewBox...
htmlwidgets::onRender(sn, 'function(el) { el.getElementsByTagName("svg")[0].removeAttribute("viewBox") }')
UPDATE 2020.04.02
My currently preferred method to do this is to use htmlwidgets::onRender to target specifically the SVG contained by the passed htmlwidget, like this...
onRender(sn, 'function(el) { el.querySelector("svg").removeAttribute("viewBox") }')
That can then be done specifically to as many htmlwidgets on your page as necessary, for instance...
onRender(sn, 'function(el) { el.querySelector("svg").removeAttribute("viewBox") }')
onRender(sn2, 'function(el) { el.querySelector("svg").removeAttribute("viewBox") }')
Related
I have shiny dashboard with two tabPanels. First tabpanel having infoboxes with date range selection and second one with radiobuttons selection for infoboxes. Second one with radiobuttons working fine when date range selection is not there is first tabpanel. But when I adding date range selection to the first tabpanel, then radiobuttons are not functioning in second tabpanel. Why does the radiobuttons are not functioning while adding date range select feature in first "tabpanel"?
Here is my code:
library(shiny)
library(shinydashboard)
library(ECharts2Shiny)
dat1 <- data.frame(
name = c("Male", "Female"),
value = c(10, 20)
)
dat2 <- data.frame(
name = c("Male", "Female"),
value = c(30, 40)
)
ui <- shinyUI(dashboardPage(
dashboardHeader(title = "123"),
dashboardSidebar(disable = TRUE),
dashboardBody(fluidPage(
tabsetPanel(
tabPanel(h5("Beneficiaries"),
fluidRow(radioButtons("Bene", "Details", c("Vis","Scre", "Sus"), inline = T),
infoBoxOutput("loc", width = 960),
loadEChartsLibrary(),
tags$div(id="test5", style="width:60%;height:300px;"),
deliverChart(div_id = "test5"), width = "800px", height = "400px")),
tabPanel(h5("summary"),
box(
infoBoxOutput("first", width = 6),
infoBoxOutput("second", width = 6), width = 8
),
box(h4("Date selection"), dateRangeInput("dateRange", "Select date range:", width =
200, submitButton(text = "Submit", icon = NULL, width = 4))
)
)
))))
server <- shinyServer(function(input,output){
output$loc <- renderInfoBox({
if (input$Ben == "Vis"){
box(h3("Vis"),
infoBox("Total", 1, width = 4),
infoBox("part", 1, width = 4),
renderPieChart(div_id = "test1", data = dat1, show.label = TRUE),
background = "black")
}
else {if (input$Ben == "Scre") {
box(h3("Scre"),
infoBox("Total", 2, width = 4),
infoBox("part", 1, width = 4),
renderPieChart(div_id = "test1", data = dat2, show.label = TRUE),
background = "black")
}
else{ box(h3("Sus"),
infoBox("Full", 3, width = 12)
)
} }}
})
})
shinyApp(ui,server)
Can anyone help on this?
Thanks a lot in advance.
Updated answer
I made some corrections to your code (there were some issues with the curly braces in you if/else statement). Not sure if that is what you intended.
library(shiny)
library(shinydashboard)
library(ECharts2Shiny)
dat1 <- data.frame(
name = c("Male", "Female"),
value = c(10, 20)
)
dat2 <- data.frame(
name = c("Male", "Female"),
value = c(30, 40)
)
ui <- shinyUI(dashboardPage(
dashboardHeader(title = "123"),
dashboardSidebar(disable = TRUE),
dashboardBody(fluidPage(
tabsetPanel(
tabPanel(h5("Beneficiaries"),
fluidRow(radioButtons("Ben", "Details", c("Vis","Scre", "Sus"), inline = T),
infoBoxOutput("loc", width = 960),
loadEChartsLibrary(),
tags$div(id = "test5", style="width:60%;height:300px;"),
deliverChart(div_id = "test5"), width = "800px", height = "400px")),
tabPanel(h5("summary"),
box(
infoBoxOutput("first", width = 6),
infoBoxOutput("second", width = 6), width = 8
),
box(h4("Date selection"), dateRangeInput("dateRange",
"Select date range:",
width = 200,
submitButton(text = "Submit", icon = NULL, width = 4)))
)
)
))))
server <- shinyServer(function(input,output){
output$loc <- renderInfoBox({
if (input$Ben == "Vis"){
box(h3("Vis"),
infoBox("Total", 1, width = 4),
infoBox("part", 1, width = 4),
renderPieChart(div_id = "test1", data = dat1, show.label = TRUE),
background = "black")
} else if (input$Ben == "Scre") {
box(h3("Scre"),
infoBox("Total", 2, width = 4),
infoBox("part", 1, width = 4),
renderPieChart(div_id = "test1", data = dat2, show.label = TRUE),
background = "black")
} else { box(h3("Sus"),
infoBox("Full", 3, width = 12))
}
})
})
shinyApp(ui,server)
I have the following piece of code:
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
library(shinyjs)
library(shinycssloaders)
library(plotly)
library(treemap)
library(viridisLite)
library(highcharter)
library(V8)
library(dplyr)
library(RColorBrewer)
library(openxlsx)
library(quantmod)
library(shinyWidgets)
library(caret)
library(lubridate)
library(tidyr)
library(flexdashboard)
xheader<-dashboardHeaderPlus( title = "ABC")
xsidebar<- dashboardSidebar(
sidebarUserPanel("USER",
subtitle = "Test",
image = "XXX"
),
sidebarMenu(id = "left_sidebar",
menuItem("DashBoard",
tabName = "ID_DashBoard",
icon = icon("desktop"))
)
)
x1body<-dashboardBody(
tabItems(
tabItem(tabName = "ID_DashBoard",
fluidRow(
column(width = 4,
fluidRow(style = "height:1000px; background-color: #E8E9EC;font-weight:bold",
column(width = 4, style = "color:green;font-weight:bold;",
gaugeOutput("gauge1", width = "100px", height = "200px")
),
column(width = 4,
gaugeOutput("gauge2", width = "100px", height = "200px")
),
column(width = 4,
gaugeOutput("gauge3", width = "100px", height = "200px")
)
)
),
column(width = 4,
fluidRow("MIDDLE", style = "height:1000px; background-color: #F2F3F5;")
),
column(width = 4,
fluidRow("RIGHT", style = "height:1000px; background-color: #E8E9EC;")
)
)
)
)
)
ui<- dashboardPagePlus(
shinyjs::useShinyjs(),
header = xheader,
sidebar = xsidebar,
body = x1body,
skin = "black",
sidebar_background = "light",
collapse_sidebar = TRUE
)
server <- function(input,output,session){
output$gauge1 = renderGauge({
gauge(0.5,
min = 0,
max = 1,
sectors = gaugeSectors(success = c(0.5, 1),
warning = c(0.3, 0.5),
danger = c(0, 0.3)),
label = "Total Commits"
)
})
output$gauge2 = renderGauge({
gauge(0.1,
min = 0,
max = 1,
sectors = gaugeSectors(success = c(0.5, 1),
warning = c(0.3, 0.5),
danger = c(0, 0.3)),
label = "Total Executed"
)
})
output$gauge3 = renderGauge({
gauge(0.1,
min = 0,
max = 1,
sectors = gaugeSectors(success = c(0.5, 1),
warning = c(0.3, 0.5),
danger = c(0, 0.3)),
label = "Total Executed"
)
})
}
shinyApp(ui, server)
The GUI looks like this currently:
as you can see in the image, the labels are not displayed properly on the grey background. I want to change the font size/color/make it bold for the following texts - Total Commits, Total Executed, Total Executed on the Gauge display and the min/max numbers on the gauge. I am unable to figure it out through CSS styling. Can someone please help me? Thanks in advance!
I have a table being display in a shiny app. I want to format the tables based on the values and color it accordingly. I have seen the formattable area coloring where based on the range of the values it defines the breaks and then color gradients are generated which are applied to the table. What I want to do is allow the user to fill the min and max value and depending on it the values in the table will be colored. So if the values range from 1-20 and if the user inputs are 5 and 15 , values below 5 and above 15 shouldnt have any color gradients applied to them. Below is the code of how I am doing currently using formatable area formatting.
library(shiny)
library(shinyWidgets)
library(shinydashboard)
library(DT)
sidebar <- dashboardSidebar(
sidebarMenu(id = "tab",
menuItem("1", tabName = "1")
)
)
body <- ## Body content
dashboardBody(box(width = 12,fluidRow(
fluidRow( column(
width = 3, textInput("text1", label = h5("Min"), value = "Enter min")),
column(
width = 3, textInput("text2", label = h5("Max"), value = "Enter max"))),
DT::dataTableOutput("op")
)))
ui <- dashboardPage(dashboardHeader(title = "Scorecard"),
sidebar,
body)
# Define the server code
server <- function(input, output,session) {
df <- data.frame(month = c("mazda 3", "mazda cx5", "mazda 6","mazda miata","honda civic","honda accord"),
april = c(.1,.2,.3,.3,.4,.5),
may = c(.3,.4,.5,.2,.1,.5),
june = c(.2,.1,.5,.1,.2,.3))
brks <- reactive({ quantile(df$april, probs = seq(.05, .95, .05), na.rm = TRUE)})
clrs <- reactive({ round(seq(255, 175, length.out = length(brks()) + 1), 0) %>%
{paste0("rgb(",.,",", ., ",255 )")}})
df_format<- reactive ({datatable(df,options = list(searching = FALSE,pageLength = 15, lengthChange = FALSE))%>%
formatStyle(names(df),backgroundColor = styleInterval(brks(), clrs()))})
output$op <-renderDataTable({
df_format()
})
}
shinyApp(ui = ui, server = server)
Here is your working code.
You must use that input minimal and maximal value as limits for your sequence (I just change it to range - is easier for user to put a range like that)
Then you generate sequence - according your notation - brks() - in my case I use length.out of 10 but you can put as many breaks as you want or dynamically.
Then generate on
number of colors - 1
and in the end in styleInterval() for background add limits of white - or any other color you want.
library(shiny)
library(shinyWidgets)
library(shinydashboard)
library(DT)
sidebar <- dashboardSidebar(
sidebarMenu(id = "tab",
menuItem("1", tabName = "1")
)
)
body <- ## Body content
dashboardBody(box(width = 12,fluidRow(
fluidRow(column(
width = 3,
sliderInput("range_value",
label = h3("Put a range value"),
min = 0,
max = 100,
value = c(5, 15)
)
)
),
DT::dataTableOutput("op")
)))
ui <- dashboardPage(dashboardHeader(title = "Scorecard"),
sidebar,
body)
# Define the server code
server <- function(input, output,session) {
df <- data.frame(month = c("mazda 3", "mazda cx5", "mazda 6","mazda miata","honda
civic","honda accord"),
april = c(9, 8, 11,14,16,1),
may = c(3,4,15,12,11, 19),
june = c(2,11,9,7,14,1))
brks <- reactive({
seq(input$range_value[1], input$range_value[2], length.out = 10)
})
clrs <- reactive({ round(seq(255, 175, length.out = length(brks()) - 1), 0) %>%
{paste0("rgb(",.,",", ., ",255)")}})
df_format<- reactive ({datatable(df,options = list(searching = FALSE, pageLength = 15, lengthChange = FALSE)) %>%
formatStyle(names(df),
backgroundColor = styleInterval(c(brks()), c('white', clrs() ,'white'))
)
})
output$op <-renderDataTable({
df_format()
})
}
shinyApp(ui = ui, server = server)
I created a sankey diagram like this:
#install.packages("networkD3")
library(networkD3)
nodes = data.frame("name" =
c("Retour", # Node 0
"niet tevreden/ontevreden", # Node 1
"fout", # Node 2
"stuk",
"adres",
"verpakking",
"gebroken/glas"))# Node 3
links = as.data.frame(matrix(c(
0, 1, 10, # Each row represents a link. The first number
0, 2, 20, # represents the node being conntected from.
0, 3, 30,
2, 4, 8,
3, 5, 10,
3, 6, 12# the second number represents the node connected to.
),# The third number is the value of the node
byrow = TRUE, ncol = 3))
names(links) = c("source", "target", "value")
sankeyNetwork(Links = links, Nodes = nodes,
Source = "source", Target = "target",
Value = "value", NodeID = "name",
fontSize= 12, nodeWidth = 30)
Working fine, however now I would like to use this plot into shiny. Therefore the did the following:
## app.R ##
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(title = "Basic dashboard"),
dashboardSidebar(),
dashboardBody(
# Boxes need to be put in a row (or column)
fluidRow(
box(plotOutput("plot1", height = 250))
)
)
)
library(networkD3)
server <- function(input, output) {
histdata <- rnorm(500)
nodes = data.frame("name" =
c("Retour", # Node 0
"niet tevreden/ontevreden", # Node 1
"fout", # Node 2
"stuk",
"adres",
"verpakking",
"gebroken/glas"))# Node 3
links = as.data.frame(matrix(c(
0, 1, 10, # Each row represents a link. The first number
0, 2, 20, # represents the node being conntected from.
0, 3, 30,
2, 4, 8,
3, 5, 10,
3, 6, 12# the second number represents the node connected to.
),# The third number is the value of the node
byrow = TRUE, ncol = 3))
names(links) = c("source", "target", "value")
output$plot1 <- renderPlot({
sankeyNetwork(Links = links, Nodes = nodes,
Source = "source", Target = "target",
Value = "value", NodeID = "name",
fontSize= 12, nodeWidth = 30)
})
output$plot2 <- renderPlot({
data <- histdata[seq_len(10)]
hist(data)
})
}
shinyApp(ui, server)
Thing is that Shiny for some reason can read the sankey diagram. If I change the code:
box(plotOutput("plot1", height = 250))
To:
box(plotOutput("plot2", height = 250))
It is plotting the histogram. So there seems to be something wrong with the sankey diagram. Any thoughts on what is causing this?
You should use the renderSankeyNetwork and sankeyNetworkOutput functions in networkD3 instead of plotOutput and renderPlot. So with your data already loaded, it would look like...
library(shiny)
library(shinydashboard)
library(networkD3)
ui <- dashboardPage(
dashboardHeader(title = "Basic dashboard"),
dashboardSidebar(),
dashboardBody(
# Boxes need to be put in a row (or column)
fluidRow(
sankeyNetworkOutput("plot")
)
)
)
server <- function(input, output) {
output$plot <- renderSankeyNetwork({
sankeyNetwork(Links = links, Nodes = nodes,
Source = "source", Target = "target",
Value = "value", NodeID = "name",
fontSize= 12, nodeWidth = 30)
})
}
shinyApp(ui, server)
Also see the example here
If you please run the script, it gives you a basic Sankey Chart in R and plotly and a data table besides. Also, there are three infoBoxes on top. When I click on the Sankey lines in the plot, I see the value in the data table using plotly_click. I want a functionality when I click on any Sankey Line, it picks "pointNumber" Column value in the data table and then multiplies by 2 and put in first infobox, by 3 in second infobox, and multiply by 4 in third infobox as in the snap attached. Thanks and please help.
## app.R ##
library(shiny)
library(shinydashboard)
library(devtools)
library(ggplot2)
library(plotly)
library(proto)
library(RColorBrewer)
library(gapminder)
library(stringr)
library(broom)
library(mnormt)
library(DT)
ui <- dashboardPage(
dashboardHeader(title = "Multiple hover"),
dashboardSidebar(
width = 0
),
dashboardBody(
infoBox("Multiply by 2", 2 * 2, icon = icon("credit-card")),
infoBox("Multiply by 3", 2 * 3, icon = icon("credit-card")),
infoBox("Multiply by 4", 2 * 4, icon = icon("credit-card")),
tags$br(),
box(title = "Sankey Chart", status = "primary",height = "455" ,solidHeader =
T,
plotlyOutput("sankey_plot")),
box( title = "Case Summary", status = "primary", height = "455",solidHeader
= T,
dataTableOutput("sankey_table"))
)
)
server <- function(input, output)
{
output$sankey_plot <- renderPlotly({
trace1 <- list(
domain = list(
x = c(0, 1),
y = c(0, 1)
),
link = list(
label = c("Case1", "Case2", "Case3", "Case4", "Case5", "Case6",
"Case7"),
source = c(0, 1, 2, 3, 4, 5, 6, 7),
target = c(11, 12, 7, 10, 13, 9, 8),
value = c(5, 6, 2, 4, 10, 6, 2)
),
node = list(label = c("R1", "R2", "R3","R4","R5","R6","R7","Blood
Test","Check Out","Discuss Results",
"MRI Scan", "Registration", "Triage and Assessment",
"X-RAY")),
type = "sankey"
)
data <- list(trace1)
p <- plot_ly()
p <- add_trace(p, domain=trace1$domain, link=trace1$link,
node=trace1$node, type=trace1$type)
p
})
output$sankey_table <- renderDataTable({
d <- event_data("plotly_click")
if(is.null(d))
{
print("Hello, Please hover to see the result" )
} else
d
})
}
shinyApp(ui, server)
Considering event_data() outputs a dataframe, the below code access that particular value pointNumber and renders dynamic UI.
Code:
## app.R ##
library(shiny)
library(shinydashboard)
library(devtools)
library(ggplot2)
library(plotly)
library(proto)
library(RColorBrewer)
library(gapminder)
library(stringr)
library(broom)
library(mnormt)
library(DT)
ui <- dashboardPage(
dashboardHeader(title = "Multiple hover"),
dashboardSidebar(
width = 0
),
dashboardBody(
uiOutput('box1'),
tags$br(),
box(title = "Sankey Chart", status = "primary",height = "455" ,solidHeader =
T,
plotlyOutput("sankey_plot")),
box( title = "Case Summary", status = "primary", height = "455",solidHeader
= T,
dataTableOutput("sankey_table"))
)
)
server <- function(input, output)
{
output$sankey_plot <- renderPlotly({
trace1 <- list(
domain = list(
x = c(0, 1),
y = c(0, 1)
),
link = list(
label = c("Case1", "Case2", "Case3", "Case4", "Case5", "Case6",
"Case7"),
source = c(0, 1, 2, 3, 4, 5, 6, 7),
target = c(11, 12, 7, 10, 13, 9, 8),
value = c(5, 6, 2, 4, 10, 6, 2)
),
node = list(label = c("R1", "R2", "R3","R4","R5","R6","R7","Blood
Test","Check Out","Discuss Results",
"MRI Scan", "Registration", "Triage and Assessment",
"X-RAY")),
type = "sankey"
)
data <- list(trace1)
p <- plot_ly()
p <- add_trace(p, domain=trace1$domain, link=trace1$link,
node=trace1$node, type=trace1$type)
p
})
output$sankey_table <- renderDataTable({
d <- event_data("plotly_click")
if(is.null(d))
{
print("Hello, Please hover to see the result" )
} else
d
})
output$box1 <- renderUI({
tagList(
infoBox("Multiply by 2", event_data("plotly_click")$pointNumber * 2, icon = icon("credit-card")),
infoBox("Multiply by 3", event_data("plotly_click")$pointNumber * 3, icon = icon("credit-card")),
infoBox("Multiply by 4", event_data("plotly_click")$pointNumber * 4, icon = icon("credit-card"))
)
})
}
shinyApp(ui, server)
Screenshot: