This experiment is using the highcharter library to create an interactive graph and returns the value selected on the graph back to the webpage. A good way to see the effect of changing inputs on the output calculations.
The Shiny application will be called Experiment3. To set things up I will need to create 4 things
1. Create an Experiment3 folder.
2. Create a server.R script file in the Experiment2 folder.
3. Create a ui.R script file in the Experiment3 folder.
4. Create an Experiment3_App.R script file outside the Experiment3 folder.
The server.R script is
The ui.R script is
The experiment3_app.R script is
Lets drag the mid point
The Shiny application will be called Experiment3. To set things up I will need to create 4 things
1. Create an Experiment3 folder.
2. Create a server.R script file in the Experiment2 folder.
3. Create a ui.R script file in the Experiment3 folder.
4. Create an Experiment3_App.R script file outside the Experiment3 folder.
The server.R script is
library(shiny)
library(highcharter)
library(data.table)
myData <- data.table(x=2012:2016, y=c(3900, 4200, 5700, 8500, 11900))
shinyServer(function(input, output) {
#Make a copy of the data table. It will be run only once when use opens the application
m_data <- myData
output$text1 <- renderText({
paste("You have selected ",input$xaxis_name)
})
output$text2 <- renderText({
paste("You have selected ",input$yaxis_name)
})
output$view <- renderTable({
m_data[x==input$xaxis_name]$y <<- input$yaxis_name
m_data})
output$hcontainer <- renderHighchart({
hc <- highchart() %>%
hc_chart(type = "line", animation=FALSE) %>%
hc_title(text = "A simple demo") %>%
hc_subtitle(text = "A subtitle") %>%
hc_xAxis(categories = m_data$x) %>%
hc_plotOptions(
series = list(
point = list(
events = list(
drop = JS("function(){
Shiny.onInputChange('xaxis_name', this.category)
Shiny.onInputChange('yaxis_name', this.y)
}")))
,stickyTracking = FALSE
),
column = list(
stacking = "normal"
),
line = list(
cursor = "ns-resize"
)) %>%
hc_add_series(
data = m_data$y,name = "Downloads",draggableY = TRUE
)
hc
})
})
The ui.R script is
library(shiny)
shinyUI(
fluidPage(
titlePanel("High Charter plotting"),
highchartOutput("hcontainer",height = "500px"),
textOutput("text1"),
textOutput("text2"),
tableOutput("view")
)
)
The experiment3_app.R script is
# Experiment 3: Using highcharter for interactive plotting and feedback
library(shiny)
runApp("experiment3")
Lets drag the mid point


Comments
Post a Comment