英文:
Filter DataTable Output based on unique observations
问题
Sure, here is the translated code:
以下是我的闪亮应用程序的代码
library(shiny)
DF = data.frame(ID = c("1","2","3","4","5"),
product = c("A","B","C","A","C"),
sentiment = c("好","中","差","中","差"),
online = c(1,0,1,1,0),
ooh = c(0,1,0,1,1),
Date= c("2020-08-11", "2020-09-16","2021-10-20", "2020-11-25", "2022-11-27"),
event = c(1,1,0,0,0))
# 定义绘制直方图的应用程序的UI
ui <- fluidPage(
# 应用程序标题
titlePanel("产品情感"),
# 侧边栏带有用于选择箱数的滑块输入
sidebarLayout(
sidebarPanel(
selectInput("selectsentiment", label = "选择情感", choices = unique(DF$sentiment)),
dateRangeInput("daterange", h5("日期范围"),
start = ymd("2020-08-11"),
end = ymd("2022-09-06"),
min = min(DF$Date),
max = max(DF$Date),
format = "yyyy-mm-dd"
)
),
# 显示生成的分布的图表
mainPanel(
dataTableOutput("DT_Table")
)
)
)
# 定义绘制直方图所需的服务器逻辑
server <- function(input, output) {
output$DT_Table <- renderDataTable({
DF[DF$sentiment %in% input$selectsentiment &
DF$Date >= input$daterange[1] &
DF$Date <= input$daterange[2],]
})
}
# 运行应用程序
shinyApp(ui = ui, server = server)
英文:
Below is a code to my shiny app
library(shiny)
DF = data.frame(ID = c ("1","2","3","4","5"),
product = c("A","B","C","A","C"),
sentiment = c("good","medium","bad","medium","bad"),
online = c(1,0,1,1,0),
ooh = c(0,1,0,1,1),
Date= c("2020-08-11", "2020-09-16","2021-10-20", "2020-11-25", "2022-11-27"),
event = c(1,1,0,0,0))
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("Product Sentiment"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
selectInput("selectsentiment", label = "Select sentiment", choices = unique(DF$sentiment)),
dateRangeInput("daterange", h5("Date range"),
start = ymd("2020-08-11"),
end = ymd("2022-09-06"),
min = min(DF$Date),
max = max(DF$Date),
format = "yyyy-mm-dd"
)
),
# Show a plot of the generated distribution
mainPanel(
dataTableOutput("DT_Table")
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
output$DT_Table <- renderDataTable({
DF[DF$sentiment %in% input$selectsentiment,]
})
}
# Run the application
shinyApp(ui = ui, server = server)
I want to filter the output of the datatable when a person does both. I.e. selecting positive or negative as well as selecting a date date range
How do I go about that?
答案1
得分: 0
请检查更新后的renderDataTable
调用:
library(shiny)
DF = data.frame(ID = c("1","2","3","4","5"),
product = c("A","B","C","A","C"),
sentiment = c("good","medium","bad","medium","bad"),
online = c(1,0,1,1,0),
ooh = c(0,1,0,1,1),
event = c(1,1,0,0,0))
# 定义应用程序的UI
ui <- fluidPage(
# 应用程序标题
titlePanel("Product Sentiment"),
# 侧边栏,用于选择柱数的滑块输入
sidebarLayout(
sidebarPanel(
selectInput("selectsentiment", label = "Select sentiment", choices = unique(DF$sentiment))
),
# 显示生成的分布的图表
mainPanel(
dataTableOutput("DT_Table")
)
)
)
# 定义绘制直方图所需的服务器逻辑
server <- function(input, output) {
output$DT_Table <- renderDataTable({
DF[DF$sentiment %in% input$selectsentiment,]
})
}
# 运行应用程序
shinyApp(ui = ui, server = server)
英文:
Please check the updated renderDataTable
call:
library(shiny)
DF = data.frame(ID = c ("1","2","3","4","5"),
product = c("A","B","C","A","C"),
sentiment = c("good","medium","bad","medium","bad"),
online = c(1,0,1,1,0),
ooh = c(0,1,0,1,1),
event = c(1,1,0,0,0))
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("Product Sentiment"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
selectInput("selectsentiment", label = "Select sentiment", choices = unique(DF$sentiment))
),
# Show a plot of the generated distribution
mainPanel(
dataTableOutput("DT_Table")
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
output$DT_Table <- renderDataTable({
DF[DF$sentiment %in% input$selectsentiment,]
})
}
# Run the application
shinyApp(ui = ui, server = server)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论