html网页嵌入shiny,Shiny - Build your entire UI with HTML

b5ee20d7286f24f9d95bd8bcc3ffeb96.png

The HTML UI application demonstrates defining a Shiny user interface using a standard HTML page rather than a UI object. To run the example type:

library(shiny)runExample("08_html")

Defining an HTML UI

Many Shiny apps use a UI object file to build their user interfaces. While this is a fast and convenient way to build user interfaces, some applications will inevitably require more flexiblity. For this type of application, you can define your user interface directly in HTML. For such apps, the directory structure looks like this:

|-- app.R

|-- www

|-- index.html

In this example we re-write the front-end of the Tabsets application (runExample("06_tabsets")) using HTML directly. Here is the source code for the new user interface definition:

www/index.html

HTML UI

Distribution type:

Normal

Uniform

Log-normal

Exponential

Number of observations:

Summary of data:

 
 

Plot of data:

style="width: 100%; height: 300px">

Head of data:

There are few things to point out regarding how Shiny binds HTML elements back to inputs and outputs:

HTML form elements (in this case a select list and a number input) are bound to input slots using their name attribute.

Output is rendered into HTML elements based on matching their id attribute to an output slot and by specifying the requisite css class for the element (in this case either shiny-text-output, shiny-plot-output, or shiny-html-output).

With this technique you can create highly customized user interfaces using whatever HTML, CSS, and JavaScript you like.

Server function

All of the changes from the original Tabsets application were to the user interface, the server script remains the same:

# Define server logic for random distribution app ----server

Building the Shiny app object

We end the app.R file with a call to the shinyApp function to build the Shiny app object using the UI and server components we defined above.

shinyApp(ui=htmlTemplate("www/index.html"),server)

Learn more

For more on this topic, see the following resources:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值