我正在尝试创建一个flexdashboard,它使用Leaflet中的事件(map_marker_click)在同一页面上的另一个图表中显示highcharts柱形图.我从其他示例中获取并且在Flexdashboards教程或示例中找不到我想要的内容. 这非常接近我想要的,没有闪亮的输入或plot.ly集成和使用标记而不是多边形(更不用说继续).
我在R中的flexdashboard有以下代码:
title: "Flexdashboards and Leaflet"
output:
flexdashboard::flex_dashboard:
vertical_layout: fill
runtime: shiny
---
```{r,include=FALSE}
library(flexdashboard)
library(shiny)
library(leaflet)
library(highcharter)
```
```{r,include=FALSE}
latitude<-c(35.94077, 35.83770, 35.84545, 35.81584, 35.79387, 36.05600)
longitude<-c(-78.58010, -78.78084, -78.72444, -78.62568, -78.64262,-78.67600)
amounts1<-c(27, 44, 34, 46, 25, 15)
amounts2<-c(34, 52, 35, 78, 14, 24)
ids<-c("a", "b", "c", "d", "e", "f")
df<-data.frame(ids,amounts1,amounts2,latitude,longitude)
renderLeaflet({
leaflet() %>%
addTiles() %>%
addMarkers(lng=c(longitude),lat=c(latitude))
})
observeEvent(input$map_marker_click,{
click<-input$map_marker_click
if(is.null(click))
return()
})
```
```{r}
renderHighchart({
highchart() %>%
hc_chart(type = 'column')%>%
hc_add_series(name=amounts1, data=click())
hc_add_series(name=amounts2, data=click())
})
```
Run Code Online (Sandbox Code Playgroud)
我想知道这是否可以在有或没有闪亮集成的flexdashboard中完成.
我有以下代码,我尝试运行失败.我只是希望能够根据输入范围过滤图形输出.在这个例子中,如果范围输入设置为1-5,我希望在图表上看到5个点,同样2-5的范围输入显示4个点.
##UI
require(shiny)
shinyUI(fluidPage(
titlePanel(title=h4("Races", align="center")
),
sidebarPanel(
sliderInput("num", "Number:",
min = 0, max = 5,step=1,value=c(0,2)),
mainPanel(
plotOutput("plot2")))))
##server
library(dplyr)
library(ggplot2)
shinyServer(function(input,output){
num<-c(1,2,3,4,5)
let<-c("A","B","C","D","E")
date<-c("2015-5-1","2015-6-1","2015-7-1","2015-8-1","2015-9-1")
df<-data.frame(num,let,date)
dat<-reactive({
df %>% filter(num==input$num)})
output$plot2<-renderPlot({
ggplot(dat(),aes(x=date,y=num))+geom_point(colour='red')},height = 400,
width = 600)})
Run Code Online (Sandbox Code Playgroud)
我想根据输入范围显示图表上的值范围,但只显示1个值,而不是具有相应日期的值范围.
提前致谢.
我试图在word文档的knitr中显示一个简单的表.我有以下代码:
library(knitr)
a<-c(1,2,3,4,5,6)
b<-c(1,2,3,4,5,6)
tab<-data.frame(a,b)
Run Code Online (Sandbox Code Playgroud)
在控制台中,这正确运行
knitr::kable(tab)
Run Code Online (Sandbox Code Playgroud)
但是,当放入称为"medinventory"的降价文档时,代码无法正常运行并返回以下错误:
````{r echo=FALSE,results='asis'}
knitr::kable(tab)
````
processing file: medinventory.Rmd
|...................... | 33%
ordinary text without R code
|........................................... | 67%
label: unnamed-chunk-1 (with options)
List of 2
$ echo : logi FALSE
$ results: chr "asis"
Quitting from lines 17-18 (medinventory.Rmd)
Error in is.data.frame(x) : object 'tab' not found
Calls: <Anonymous> ... eval -> eval -> <Anonymous> -> colnames ->
is.data.frame
Execution halted
Run Code Online (Sandbox Code Playgroud)
那么数据框是在globalEnvr中,但是没有被markdown识别?我将不胜感激任何相关问题的链接以及答案.