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

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.

主站蜘蛛池模板: 济南市| 朔州市| 凤翔县| 长沙县| 宁强县| 司法| 临清市| 安仁县| 日照市| 仁化县| 泸西县| 德钦县| 墨竹工卡县| 正镶白旗| 成安县| 鲜城| 江山市| 中宁县| 克拉玛依市| 安康市| 姜堰市| 军事| 宁乡县| 五寨县| 隆安县| 杭锦后旗| 茂名市| 阿合奇县| 平潭县| 五台县| 肥东县| 朝阳市| 个旧市| 法库县| 齐河县| 依兰县| 阳西县| 班戈县| 库车县| 沙湾县| 西乡县|