在Shiny中使用动态高图表中的返回数据 [英] Use return data from dynamic highcharts chart in Shiny
问题描述
我在Shiny中实现了一个图形,用户可以使用 http://jkunst.com/highcharter/oldindex.html#draggable-points 示例。我想使用server.r中的新数据点并将它们显示在一个表中。如果有人能够帮助我如何返回数据点,那就太好了。请查找下面的代码。
谢谢,TIm
server.r:
data(citytemp,package =highcharter)
function输入,输出){
hcbase< - reactive({
#hcbase< - function()highchart()
hc< - highchart()
if(input $ credits)
hc< - hc%>%hc_credits(enabled = TRUE,text =Highcharter,href =http://jkunst.com/highcharter/)
$ b $ if(input $ exporting)
hc< - hc%>%hc_exporting(enabled = TRUE)
if(input $ theme!= FALSE) {
theme< - switch(input $ theme,
null = hc_theme_null(),
economist = hc_theme_economist(),
dotabuff = hc_theme_db(),
darkunica = hc_theme_darkunica(),
gridlight = hc_theme_gridlight(),
sandsignika = hc_theme_sandsignika(),
fivethirtyeight = hc_theme_538(),
chalk = hc_theme_chalk(),
handdrwran = hc_theme_handdrawn()
)
hc < - hc%>%hc_add_theme(主题)
}
hc
})
输出$表< -renderDataTable({
#Output from graph
data.table(month = citytemp $ month,berlin = citytemp $ berlin $ b $,berlin_dragged = citytemp $ berlin)#这里我想用拖动的数据。 linke input $ highchart $ ...应该这样做我猜...
})
输出$ highchart< - renderHighchart({
data (citytemp)
highchart()%>%
hc_chart(animation = FALSE)%>%
hc_title(text =可拖动积分演示)%>%
hc_xAxis(categories = month.abb)%>%
hc_plotOptions(
series = list(
stickyTracking = FALSE
),
column = list (
stacking =normal
),
line = list(
cursor =ns-resize
)
)%>%
hc_add_series(
data = citytemp $柏林,
draggableY = TRUE
)
})
$ b ui.r
library(shiny)
library(shinydashboard)
library(highcharter)
library(dplyr)
library(viridisLite)
library(markdown)
library(quantmod)
library(tidyr)
library(ggplot2)
library(treemap)
library(fore (
$ b $ (title =highcharter,disable = FALSE),
dashboardSidebar(
sidebarMenu(
menuItem(Examples,tabName =examples,icon = icon(bar-chart)) )
)
#,
#div(includeMarkdown(hcterinfo.md),style =padding:10px)
),
dashboardBody(
#tags $ head(tags $ script(src =js / ga.js)),
#tags $ head(tags $ link(rel =stylesheet,type =text / css,
tabItems(
tabItem(tabName =examples,
fluidRow(
box(width = 6, highchartOutput(highchart)),
box(width = 6,dataTableOutput(table))
)
)
)
))
关键部分是:
$ b
- 在highcharts中使用drop事件(JS代码)。
- 在前面的代码事件中,使用Shiny.onInputChange('inputname',data)。这告诉闪亮的是,手动预览数据已经改变,因此您可以在渲染函数中使用。 然后创建一个renderObject(renderTable)调用输入$ inputname。因此,您可以获取更新的数据并执行任何您想要的操作。
密码行
hc_plotOptions(
series = list(
point = list(
events = list(
drop = JS(function (){
console.log(this.series)
window.data = _.map(this.series.data,function(e){return ey))
Shiny.onInputChange 'inputname',data);
}))
)))
然后:
renderDataTable({
...
var < - input $ inputname#听取放映活动
...
参考: https://github.com/jbkunst/shiny-apps/blob/master/highcharter/server .R#L158
I'm implementing a graph in Shiny where users can create their own time series with the "draggable point" option from the http://jkunst.com/highcharter/oldindex.html#draggable-points example. I would like to use the "new" datapoints in server.r and also show them in a table. If someone could help me how to return the data points, that would be great.Please find the code below.
Thanks, TIm
server.r:
data(citytemp, package = "highcharter")
function(input, output) {
hcbase <- reactive({
# hcbase <- function() highchart()
hc <- highchart()
if (input$credits)
hc <- hc %>% hc_credits(enabled = TRUE, text = "Highcharter", href = "http://jkunst.com/highcharter/")
if (input$exporting)
hc <- hc %>% hc_exporting(enabled = TRUE)
if (input$theme != FALSE) {
theme <- switch(input$theme,
null = hc_theme_null(),
economist = hc_theme_economist(),
dotabuff = hc_theme_db(),
darkunica = hc_theme_darkunica(),
gridlight = hc_theme_gridlight(),
sandsignika = hc_theme_sandsignika(),
fivethirtyeight = hc_theme_538(),
chalk = hc_theme_chalk(),
handdrwran = hc_theme_handdrawn()
)
hc <- hc %>% hc_add_theme(theme)
}
hc
})
output$table <-renderDataTable({
#Output from graph
data.table(month=citytemp$month,berlin=citytemp$berlin
,berlin_dragged=citytemp$berlin)#Here I want to use the dragged data. something linke input$highchart$... should do the trick I guess...
})
output$highchart <- renderHighchart({
data(citytemp)
highchart() %>%
hc_chart(animation = FALSE) %>%
hc_title(text = "draggable points demo") %>%
hc_xAxis(categories = month.abb) %>%
hc_plotOptions(
series = list(
stickyTracking = FALSE
),
column = list(
stacking = "normal"
),
line = list(
cursor = "ns-resize"
)
) %>%
hc_add_series(
data = citytemp$berlin,
draggableY = TRUE
)
})
}
ui.r
library("shiny")
library("shinydashboard")
library("highcharter")
library("dplyr")
library("viridisLite")
library("markdown")
library("quantmod")
library("tidyr")
library("ggplot2")
library("treemap")
library("forecast")
library("DT")
rm(list = ls())
dashboardPage(
skin = "black",
dashboardHeader(title = "highcharter", disable = FALSE),
dashboardSidebar(
sidebarMenu(
menuItem("Examples", tabName = "examples", icon = icon("bar-chart"))
)
#,
#div(includeMarkdown("hcterinfo.md"), style = "padding:10px")
),
dashboardBody(
# tags$head(tags$script(src = "js/ga.js")),
# tags$head(tags$link(rel = "stylesheet", type = "text/css", href = "css/custom_fixs.css")),
tabItems(
tabItem(tabName = "examples",
fluidRow(
box(width = 6, highchartOutput("highchart")),
box(width = 6, dataTableOutput("table"))
)
)
)
))
The key parts are:
- In highcharts use the drop event (JS code).
- In the previous code event use the Shiny.onInputChange('inputname', data). This tell shiny that manualforecast data has change so you can use in a render function.
- Then create a renderObject (renderTable) calling input$inputname. So you can get the updated data and do whatever you want.
Key lines of code
hc_plotOptions(
series = list(
point = list(
events = list(
drop = JS("function(){
console.log(this.series)
window.data = _.map(this.series.data, function(e) { return e.y })
Shiny.onInputChange('inputname', data);
}"))
)))
And then:
renderDataTable({
...
var <- input$inputname # listening the drop event
...
Reference: https://github.com/jbkunst/shiny-apps/blob/master/highcharter/server.R#L158
这篇关于在Shiny中使用动态高图表中的返回数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!