-3

In Rmarkdown to generate a flexdashboard, I want to import an excel sheet and use selectInput statement to select any of 2,3,4,5 columns (product1,product2,product3,product4) from excel sheet and plot a scatter chart for column1(Day) vs selected column from selectInput statement(product1 or product2 or product3 or product4). Can someone please help me with the R code?enter image description here

--- title: "General plots" author: "Aravind" date: "April 1st,2018" output: flexdashboard::flex_dashboard: orientation: columns

runtime: shiny

{r, echo=FALSE} library(readxl) library(flexdashboard) library(shiny) library(plotly) data_to_plot<-read_excel("random.xlsx") Inputs {.sidebar} {r Global Filter Panel, echo=FALSE} selectInput("Product","Activity",choices=c('product1','product2','product3','product4'),selected=NULL,width = '400px') Under this tab chart will be displayed

Chart {.tabsets .tabset-fade}

Chart ```{r echo=FALSE, message=FALSE}

renderPlotly(
p<-plot_ly( data_to_plot,x=~Product,y=~Day, color ="red", type="scatter")%>% layout(title="Scatter plot using R plotly", xaxis=list(title="Day"),yaxis=list(title="Product"), legend=list(x=1,y=0.5))%>% p )

```

Praneeth
  • 11
  • 3
  • Show us what you've tried so far. Where is your code attempt? Where did you get stuck? There are plenty of tutorials/resources available that would get you started. SO is not a free code writing service. You need to demonstrate some effort! Also please review [how to ask](https://stackoverflow.com/help/how-to-ask) questions here on SO. – Maurits Evers Apr 02 '18 at 08:12
  • Hi Maurits, I'm new to SO and thanks for your suggestion. – Praneeth Apr 03 '18 at 06:39
  • I have included the code that i have tried so far in the description. Please do let me know where i'm making the mistake or how should i approach it. – Praneeth Apr 03 '18 at 06:59

1 Answers1

1

Little bit of messy formatting in your question that you might want to fix but the answer isn't too hard.

You used

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

So, a input selection with inputID=Product. In shiny / flexdashboard this will create a variable input$Product.

Then you use plot_ly() with

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

Here you use the Product variable, which isn't assigned anywhere unless it's a column in your dataframe. Instead try this,

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

Hence, use input$Product to get the value from your Shiny selectInput(). Hope that will get you going. I'm sure this will look familiar to you if you've gone through some tutorials on flexdashboards.

  • Thanks for the help @Lodewic Van Twillert, it worked. Can you please suggest a solution for this as well [link](https://stackoverflow.com/questions/49859564/deploy-rmarkdown-web-app-on-server). Eagerly waiting for your answer...thanks in advance – Praneeth Apr 17 '18 at 06:54