I am new to R .I am creating a dashboard with date ranges and I have one dropdown for column names of the data table and I need to create another dropdown of column commenttype(i.e., good or bad) that is based on first dropdown and need to plot it in area chart in such a way that dates are on x axis y axis is the metric of the column and color by the second dropdown. How to do it? My data table is like with columns Username, comment, dates, posts, sentiment analysis[i.e., 0 and 1's], commenttype [i.e., good or bad]. Below is my code
library(dplyr)
library(shiny)
library(plotly)
library(dplyr)
library(data.table)
library(shinyjs)
ui <- fluidPage(
useShinyjs(),
{
tags$head(
tags$style(
HTML(".circle{position:relative; display:inline-block; border:1px solid black; border-radius: 50px; width: 20%;height:0; text-align: center;margin-left: 20px;margin-right: 50px;top: 29px;}
")))},
tabsetPanel({
tabPanel("Comments by dates",
fluidRow(column(4, dateRangeInput('dateRange', label = 'Filter comments by date', start = min(comments$dates) , end = max(comments$dates)))),
fluidRow(column(4,selectInput("names", "Select Data", choices=c("Posts" = "post_id","Comments" = "comment","users" = "User_name","Sentiment" = "commenttype")))),
fluidRow(column(4,selectInput("types","select types",choices=unique(comments$commenttype)))),
fluidRow((column(12,htmlOutput('Summary')))),
fluidRow(column(12,plotlyOutput("Bar")))
)
})
)
server <- function(input, output, session) {
output$Summary <- renderUI({
comments = comments[,commenttype:=ifelse(SA==-1,'bad',ifelse(SA==0,'DontKnow','Good')),]
comments = comments[dates >= input$dateRange[1] & dates <= input$dateRange[2]]
Posts = length(unique(comments$post_id))
Comments = length(unique(comments$comment))
Users = length(unique(comments$User_name))
HTML(paste("<div>
<div class='.circle'>",Posts,"</div>
<div class='.circle'>",Comments,"</div>
<div class='.circle'>",Users,"</div>
</div>
"))
})
output$Bar <- renderPlotly({
plotdata = comments
plotdata
plotdata$Metric <- plotdata %>% pull(input$names)
plotdata$Metric
plotdata=plotdata[,metric:=list(length(unique(Metric))),by=.(dates)]
plotdata
p <- plot_ly(x = ~plotdata$dates, y = ~plotdata$metric, type = 'scatter', mode = 'lines', fill = 'tozeroy') %>%
layout(xaxis = list(title = 'dates',showgrid = FALSE),
yaxis = list(title = 'Metric',showgrid = FALSE))
p
})
}
shinyApp(ui, server)
All I need is create another drop-down for commenttype column values and when I click on other column names like comment, user I need to get area chart for that particular column the commenttype values must be shown on area chart with xaxis as date and y axis as the count of the columns and color by the commenttype values. Can you please help me?