【问题标题】:Generate flexdashboard in Rmarkdown在 Rmarkdown 中生成 flexdashboard
【发布时间】:2018-09-11 10:44:08
【问题描述】:

在 Rmarkdown 中生成 flexdashboard,我想导入一个 excel 工作表并使用 selectInput 语句从中选择 2、3、4、5 列(product1、product2、product3、product4)中的任何一个excel表并绘制column1(Day)与selectInput语句(product1或product2或product3或product4)中选定列的散点图。有人可以帮我写 R 代码吗?enter image description here

--- 标题:“一般情节” 作者:“Aravind” 日期:“April 1st,2018” 输出: flexdashboard::flex_dashboard: 方向:列

运行时:闪亮

{r, echo=FALSE} library(readxl) library(flexdashboard) library(shiny) library(plotly) data_to_plot<-read_excel("random.xlsx") 输入 {.sidebar} {r Global Filter Panel, echo=FALSE} selectInput("Product","Activity",choices=c('product1','product2','product3','product4'),selected=NULL,width = '400px') 在这个标签下会显示图表

图表 {.tabsets .tabset-fade}

图表```{r echo=FALSE, message=FALSE}

renderPlotly(
p% layout(title="使用R plotly散点图", xaxis=list(title="Day"),yaxis=list(title="Product"), 图例=列表(x=1,y=0.5))%>% p)

```

【问题讨论】:

  • 向我们展示您迄今为止的尝试。您的代码尝试在哪里?你在哪里卡住了?有很多可用的教程/资源可以帮助您入门。 SO 不是免费的代码编写服务。你需要表现出一些努力!也请在 SO 上查看how to ask 问题。
  • 嗨 Maurits,我是 SO 新手,感谢您的建议。
  • 我已经在描述中包含了我迄今为止尝试过的代码。请让我知道我在哪里犯了错误或者我应该如何处理它。

标签: r shiny r-markdown flexdashboard


【解决方案1】:

您可能想要解决的问题中的一些混乱格式,但答案并不难。

你用过

   selectInput("Product","Activity",choices=c('product1','product2','product3','product4'),selected=NULL,width = '400px')

因此,inputID=Product 的输入选择。在 shiny / flexdashboard 中,这将创建一个变量input$Product

然后你使用plot_ly()

plot_ly( data_to_plot,x=~Product,y=~Day....

在这里您使用Product 变量,除非它是您数据框中的一列,否则它不会分配到任何地方。不如试试这个,

plot_ly( data_to_plot,x=~input$Product,y=~Day....

因此,使用 input$Product 从您的 Shiny selectInput() 中获取值。 希望这会让你继续前进。如果您已经阅读了有关 flexdashboards 的一些教程,我相信您会对此感到熟悉。

【讨论】:

  • 感谢@Lodewic Van Twillert 的帮助,它成功了。您能否也为此提出一个解决方案link。急切地等待您的回答...提前谢谢
猜你喜欢
  • 1970-01-01
  • 2017-10-27
  • 2022-01-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-12-09
  • 1970-01-01
  • 2016-01-30
相关资源
最近更新 更多