This is a Shiny app built on top R script to demo the use case of being able to interactively select points from a plot and have these added to a data table. We use the Plotlty library for displaying plot as it provides functionality zoom and pan the chart, and hover on points out of the box. The app augments the functionality with interactive clicking on points to add them to a table. The table is implemented using the Data Table library.
- The
onRender
event handler of Plotly is coupled to thesetInputValue
function of Shiny to handle click events on the plot on the Shiny server. - The
ID
column in the table has a dummy hyperlink to demo how hyperlinks may be implemented. - The table has a fourth column with a
Fire
button. When pressed, theID
of the corresponding row is shown below the table. - The table has buttons to download the data in various formats. This functionality comes out of the box with the
Buttons
extension of Data Tables. However one problem with the default implementation is that it writes out all the columns which would include the column with the Fire button. This implementation omits the 4th column from being written out. - The user may select rows in the table and click the
Delete
button to removed them. A potentially conflict then arises between selecting a row and pressing theFire
button. In this implementation, clicking theFire
button will not change the selection status of the row. - There are two ways to load data into the plot:
- New random data can be generated by using a slider to select the number of points desired and clicking on
Generate dataset!
. - There is a selection of saved data files in the
data
directory that can be loaded by selecting them and pressing theLoad dataset
button. One of the files,Points 20 no y
, has been modified to remove they
column to show how the validation works using theshinyFeedback
library.
- New random data can be generated by using a slider to select the number of points desired and clicking on
- The
shinythemes
library is used to skin the application.
Clone/download the repository and run it using R Studio
or R script
. Any required libraries will be installed when the script is run unless they have been already installed.
To run it from the command line (assuming you have R script
installed and PROJECT_DIR is where the project has been installed, e.g., "./PlotlyDataTableDemo"):
R -e "shiny::runApp(PROJECT_DIR)"
The required uninstalled libraries will be downloaded and installed and when the script is running you will be given a URL that has to be copy and pasted into a web browser. Here is a small snippet of a typical output:
Loading required package: purrr
Loading required package: shinyFeedback
Loading required package: shinythemes
Loading required package: vroom
Listening on http://127.0.0.1:4859
A live demo of the app can be found at https://patwar.shinyapps.io/PlotlyDataTableDemo/.
The project is distributed under the Apache-2.0
license and the details can be found in the LICENSE file.