[英]Replicating exact plots from R in basic HTML
the given script creates four plots in four boxes in R shiny dashboard page.I want to replicate the same four plots in the same manner in the following html script below the R code, and then embed the html template to make them available in R using Run App command. 给定的脚本在R闪亮的仪表板页面的四个框中创建了四个图。我想以相同的方式在R代码下方的以下html脚本中复制相同的四个图,然后嵌入html模板以使用运行应用程序命令。 I am not able to achieve the plots, please help. 我无法实现目标,请帮忙。 Thank you so much. 非常感谢。
## app.R ##
library(shiny)
library(shinydashboard)
library(devtools)
library(proto)
library(RColorBrewer)
library(gapminder)
library(broom)
library(mnormt)
ui <- dashboardPage(
dashboardHeader(title = "R to Html"),
dashboardSidebar(
width = 0
),
dashboardBody(
box(title = "Select the Data",selectInput("choice","Select the data",
choices = c("data1","data2","data3")),
status = "primary",solidHeader = T, height = "162"),
box(title = "Select the Slider Input", status = "primary",solidHeader = T,
sliderInput("slide","Select the value from slider", min = 1, max = 4,
value = 1)),
box(title = "Iris Plot", status = "primary",height = "435", solidHeader = T,
plotOutput("plot1")),
box( title = "Iris Plot", status = "primary", height = "435",solidHeader =
T, plotOutput("plot2"))
)
)
server <- function(input, output)
{
output$plot1 = renderPlot ({
plot(iris$Sepal.Length)
})
output$plot2 = renderPlot ({
plot(iris$Sepal.Width)
})
}
shinyApp(ui, server)
**# HTML code:**
<html>
<head>
<title>Dashboard Page</title>
<body>
{{box1}}
{{box2}}
{{box3}}
{{box4}}
</body>
</html>
To help you get started, I've modified a basic bootstrap template from w3schools and modified it to output shiny elements. 为了帮助您入门,我从w3schools修改了一个基本的引导程序模板,并对其进行了修改以输出闪亮的元素。
Based on our discussion, to include a theme, I've used the bootstrap theme united https://bootswatch.com/united/ 根据我们的讨论,为了包含一个主题,我使用了联合引导主题https://bootswatch.com/united/
HTML template - template1.html
HTML模板template1.html
<!DOCTYPE html>
<html lang="en">
<head>
{{ headContent() }}
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://bootswatch.com/united/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h1>Grid</h1>
<p>This example demonstrates a 50%/50% split on small, medium and large devices. On extra small devices, it will stack (100% width).</p>
<p>Resize the browser window to see the effect.</p>
<div class="row">
<div class="col-sm-6">
{{sliderInput("slide","Select the value from slider",min= 1,max = 4,value =1)}}
</div>
<div class="col-sm-6" style="background-color:pink;">
{{choices = c("data1","data2","data3")}}
</div>
</div>
<div class="row">
<div class="col-sm-6">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Plot 1</h3>
</div>
<div class="panel-body">
{{plotOutput('plot1')}}
</div>
</div>
</div>
<div class="col-sm-6">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Plot 2</h3>
</div>
<div class="panel-body">
{{plotOutput('plot2')}}
</div>
</div>
</div>
</div>
</div>
</body>
</html>
app.R file
: app.R file
:
## app.R ##
library(shiny)
library(shinydashboard)
library(devtools)
#library(proto)
#library(RColorBrewer)
#library(gapminder)
#library(broom)
#library(mnormt)
ui <- shinyUI(
htmlTemplate("template1.html")
)
server <- function(input, output)
{
output$plot1 = renderPlot ({
plot(iris$Sepal.Length)
})
output$plot2 = renderPlot ({
plot(iris$Sepal.Width)
})
}
shinyApp(ui, server)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.