官术网_书友最值得收藏!

An optional exercise

If you want to have a practice before we move on, take the existing code and modify it so that the output is a plot of a user-defined number of observations, with the text as the title of the plot. The plot call should look like the following:

hist(rnorm(XXXX), main = "YYYY") 

In the preceding line of code, XXXX is a number taken from a function in ui.R that you will add (sliderInput() or numericInput()) and YYYY is the text output we already used in the minimal example. You will also need to make use of renderPlot(); type ?renderPlot in the console for more details.

So far in this chapter, we have looked at a minimal example and learned about the basic commands that go in the server.R and ui.R files. Thinking about what we've done in terms of reactivity, the ui.R file defines a reactive value, input$comment. The server.R file defines a reactive expression, renderText(). It depends on input$comment.

Note that this dependence is defined automatically by Shiny. The renderText() expression uses an output from input$comment, so Shiny automatically connects them. Whenever input$comment changes, renderText() will automatically run with the new value. The optional exercise gave two reactive values to the renderPlot() call, and so, whenever either changes, renderPlot() will be rerun. In the rest of this chapter, we will look at an application that uses some slightly more advanced reactivity concepts, and by the end of the book, we will have covered all the capabilities that Shiny offers and when to use them.

主站蜘蛛池模板: 丹巴县| 庄浪县| 古田县| 广安市| 鲁甸县| 丰都县| 泰宁县| 容城县| 武强县| 合江县| 大港区| 阳朔县| 靖江市| 吉木萨尔县| 芷江| 德江县| 开封市| 荆门市| 清河县| 鄂尔多斯市| 开平市| 思茅市| 东方市| 丽江市| 儋州市| 钟祥市| 株洲市| 旺苍县| 金堂县| 彰武县| 云和县| 吴堡县| 红安县| 贵德县| 仙桃市| 霞浦县| 潞西市| 颍上县| 银川市| 横山县| 隆尧县|