Watch videos with subtitles in your language, upload your videos, create your own subtitles! Click here to learn more on "how to Dotsub"

06 Creating Interactive Documents

0 (0 Likes / 0 Dislikes)
This section of Introduction to Wolfram Notebooks is about making notebooks into interactive documents and more specifically about setting up tools, like the buttons in this first example for navigating through data or linking to other documents, and features, like the sliders in this second example that provide interactive controls for running programs and doing calculations for within a notebook. Probably the most common interactive feature of modern documents is a simple hyperlink, which is typically a link to another document. For example, here is a notebook with gross domestic product or GDP data for a group of seven countries called the G7. In this notebook G7 is a hyperlink, which has been set up so that clicking that link brings up a webpage. Hyperlinks can be created using the Hyperlink button from the Insert menu. For example, to create a hyperlink for the term GDP, select GDP in the notebook, then choose Hyperlink from the Insert menu, which brings up a dialog box where I can enter the destination of the link. For this example, I will enter a web address and click OK, and after that clicking GDP in the notebook opens that webpage. Hyperlinks are a common way of organizing sets of related documents so that users of the documents can follow hyperlinks to the information that they want to see. For example, this notebook is arranged in sections. So to see information on one of the countries, I can scroll through the notebook and open a section, but the information in each section could also have been organized with a separate notebook for each section, like the notebook shown here and linked to the original notebook using hyperlinks. To create one of those hyperlinks, I will start in the original notebook, select the name of a country, open the hyperlink dialog box and click the Browse button to open the file browser, where I will choose a notebook as the destination of the link. Returning to the original notebook, the selected text is now a hyperlink that I can click to open the other notebook. Organizing information into a set of hyperlinked notebooks is especially useful in more complex projects, where documents might come from different sources or be created by different people. This hyperlink will only work on a computer that also has all of the linked notebooks, but the linked notebook could also have been saved in the cloud so that the hyperlink would work on any computer that is connected to the cloud. For example, here is another notebook where I will choose Publish to Cloud to make the notebook available in the cloud. Then copy the URL for use in the hyperlink and create a hyperlink as before, using the hyperlink dialog box. Clicking that hyperlink opens the saved notebook in a web browser. So that is a way of setting up linked documents that will work on any computer that is connected to the cloud. You can also use hyperlinks to navigate within a notebook. Hyperlinks within a notebook work primarily by linking to tagged cells. To add a tag for a cell, I can select the cell and choose Add/Remove Cell Tags from the Cell Tag submenu under the Cell menu, which brings up this dialog box where I can enter a tag. After entering the tag, click the Add button to add that tag, and then set up the hyperlink as before using the hyperlink dialog box. In the dialog box, I will click the button to use cells with the selected tag as the destination. Choose a tag and click OK to create the hyperlink. Clicking that hyperlink jumps to the tagged cell within this notebook. Another way of setting up navigation through the information in a notebook is with tools called views. The basic idea is illustrated by this example, which shows a function called TabView that provides a row of buttons for displaying different images. The same system can also be used to display the information in this notebook. For example, here is a TabView input that gives a display with a row of buttons, that can be clicked to display data for each country. There are several other functions like the TabView function. For example, this shows a function called MenuView that gives a menu instead of a row of buttons. Views can also be nested. For example, this shows a TabView in which each displayed expression is another tab view, which is used here for selecting a pair of countries to include in the plot. The best way of setting up interactive navigation through a document depends, of course, on what is in the document and on who will be using it, but all of these functions have lots of options and in the documentation there are good tutorials and lots of examples for learning about the possibilities. So far the examples have mostly involved navigating through a fixed set of information, but notebooks can also include buttons and sliders and other controls for controlling programs and doing calculations. One tool for setting up controls like that is the Manipulate function. Here is a simple Manipulate input that gives a result with a slider for adjusting the frequency of a sine wave in a plot. Here is the example that was shown earlier. This example is a little more complicated, but the basic idea is the same. The first argument in Manipulate gives the calculation to do and the result to display and the other arguments specify the controls. The calculation in this example involves plotting a numerical solution of a differential equation, and there are two sliders for adjusting parameters in the differential equation. The sliders in that result use a general system for dynamically updating calculations whenever there is a change in a parameter that is used in that calculation. Normally if a parameter is used in a calculation, such as the parameter <i>x</i> in this plot, the calculation does not get redone if the parameter is changed. This plot, for example, does not get regenerated if I change the value of <i>x</i>. To get a result that will be dynamically updated, I can enclose the result in Dynamic. Unlike the previous output, this plot does change whenever the value of <i>x</i> is changed. One way of changing the value of <i>x</i> is with a slider. For example, this input gives a slider for setting the value of <i>x</i> to a number between 0 and 10. The Dynamic function is used in the slider input to indicate that changes should cause automatic updating. The result is a slider that controls the plot. Wolfram Notebooks support a variety of controls other than sliders. For example, here is a control called an Animator for continuously updating the value of a parameter. Here is another control called a RadioButtonBar that gives a row of buttons for setting the value of <i>x</I>. Another common interactive control is a menu. This input gives a pop-up menu for setting the value of <i>x</i>. Interactive features like these can be useful for illustrating concepts or to allow someone using the document to do their own calculations. For example, this shows a modified version of the earlier Manipulate example, this time including an animation of a corresponding mechanical system. Interactive illustrations like this are often quite helpful for explaining complicated topics. The programming for this example has been hidden by closing the cell group. I can double-click on the cell bracket to open the cell group and show the input that produced this result. Most of the programming is associated with constructing the images in the display. The controls are specified in just a few lines of code at the end. This last specification, for example, is the code that creates this control, called a Trigger, that initiates the animation. These controls also work in the cloud. For example, this first input generates a list of the components of the Dow Jones Industrial Average and after that, here is a Manipulate for plotting closing prices of those components. The control in this result is a menu for choosing the component to plot. Rather than choosing Publish to Cloud from the File menu to publish this entire notebook, this time I will use the CloudPublish function to publish just the Manipulate output. The result is a link that I could send to other people or that here, I will enter into a web browser to show a notebook with that same interactive display. This result is similar in appearance to the MenuView example shown earlier, but making a choice in this result causes a new plot to be generated using current data rather than selecting from pre-existing plots. So this is a good approach for sharing documents with information that might change. That's the end of the examples for the section. You can find more information on View functions, like TabView and MenuView, in the Wolfram documentation by searching for views and navigating to this page on view functions. For information on Manipulate, a good place to start is the documentation for the Manipulate function. There are also several tutorials on Manipulate and on controls in general, and this guide page on control objects lists all of the various controls like the sliders and popup menus and other controls that came up in this section.

Video Details

Duration: 8 minutes and 23 seconds
Language: English
License: Dotsub - Standard License
Genre: None
Views: 17
Posted by: wolfram on Jan 21, 2020

06 Creating Interactive Documents

Caption and Translate

    Sign In/Register for Dotsub to translate this video.