简体   繁体   中英

R Shiny HTML UI does not work properly

I would like to make a full HTML UI with Rstudio Shiny according to this description but I have a strange problem:

When I try to load the webpage the plot does not displays but if I load the ui.r (which is fully equivalent) at first and then load the HTML ui again it works.

Here is a minimal example:

# server.r
# This is always the same with ui.r and also with HTML UI

library(shiny)
library(networkD3)

data(MisLinks)
data(MisNodes)

server <- function(input, output) {

  output$force <- renderForceNetwork({
    forceNetwork(Links = MisLinks, Nodes = MisNodes, Source = "source",
                 Target = "target", Value = "value", NodeID = "name",
                 Group = "group", opacity = 1)
  })

}

and then:

<!--this is the HTML UI-->
<!DOCTYPE html>
<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>  <script type="application/shiny-singletons"></script>  <script type="application/html-dependencies">json2[2014.02.04];jquery[1.11.3];shiny[0.13.2];htmlwidgets[0.6];d3[3.5.2];forceNetwork-binding[0.2.13];bootstrap[3.3.5]</script><script src="shared/json2-min.js"></script>
<script src="shared/jquery.min.js"></script>
<link href="shared/shiny.css" rel="stylesheet" />
<script src="shared/shiny.min.js"></script>
<script src="htmlwidgets-0.6/htmlwidgets.js"></script>
<script src="d3-3.5.2/d3.min.js"></script>
<script src="forceNetwork-binding-0.2.13/forceNetwork.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="shared/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
<script src="shared/bootstrap/js/bootstrap.min.js"></script>
<script src="shared/bootstrap/shim/html5shiv.min.js"></script>
<script src="shared/bootstrap/shim/respond.min.js"></script>

</head>

<body>
  <div class="container-fluid">
    <div id="force" style="width:100%; height:500px; " class="forceNetwork html-widget html-widget-output"></div>
  </div>
</body>

</html>

The network plot does not displays for me. But if I run this at first and then the HTML UI it works:

# ui.r
# this is the equivalent version of HTML UI
library(shiny)

ui <- fluidPage(
  forceNetworkOutput("force")
) 

I have tried also with visNetwork graph and there was the same problem.

Problems that js of D3 and htmlwidgets not loading( 404 error).

You can copy all needed js into www and change path in HTML

<script src="htmlwidgets.js"></script>
<script src="d3.min.js"></script>
<script src="forceNetwork.js"></script>

It s solve problem , but its may be not best idea

Same problem on git with htmlwidgets

Update

Files you can find in you package folders : for me :

......R\R-3.2.5\library\htmlwidgets\www\
......R\R-3.2.5\library\networkD3\htmlwidgets\
......R\R-3.2.5\library\networkD3\htmlwidgets\lib\d3-3.5.2

How to check that the problem wuth js

1) Run App

2) Right click + inspect 在此输入图像描述

3) Look errors 在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM