我有一个闪亮的应用程序,根据搜索显示许多产品。 它对一个大型数据集进行子集,并向我显示我想要匹配的产品。
我有另一个数据框,其中包含所述产品的评论。
我希望在单击特定行时,审阅信息显示在不同的数据表中。
第二个数据表也需要是基于目录号的子集(此处为A
列。
所有帮助表示赞赏。
df1 <- data.frame(A= c("BX002","BX006", "BX008"),
B= c("Actin","Tubulin", "GAPDH"),
C = c("Mouse","Human", "Human"),
D = c("WB","WB", "IHC"))
df2 <- data.frame(A= c("BX002","BX006", "BX008"),
B= c("Actin","Tubulin", "GAPDH"),
C = c("5","5", "4"),
D = c("Good","Good", "Bad"),
E = c("Kidney", "Liver", "Heart"))
library(shinydashboard)
library(shiny)
app <- shinyApp(
ui = dashboardPage(
dashboardHeader(
title = "Search"),
dashboardSidebar(
sidebarMenu(
menuItem("Search Product", tabName = "product", icon = icon("search")))),
dashboardBody(
tabItems(
tabItem("product",
fluidPage(
sidebarLayout(
sidebarPanel(textInput("name", "Protein name", value = ""),
submitButton("Search")),
mainPanel(
tabsetPanel(
tabPanel("Products", dataTableOutput("table1")))))))))),
server = shinyServer(function(input, output, session) {
output$table1 <- DT::renderDataTable({
validate(need(input$name != "", "Please select a Protein Name"))
search <- input$name
df <- subset(df1, grepl(search, df1$B, ignore.case = TRUE)==TRUE)
datatable(df, escape = FALSE, selection = "single")
})
observeEvent(input$table1_rows_selected,
{
df <- subset(df2, df2$A == input$table1_rows_selected$A)
showModal(modalDialog(
title = "Reviews",
df
))
})
})
)
我尝试了一些方法,但无法使其正常工作。
这是我的最后一次尝试,没有弹出框,没有任何错误信息。
最好的
答案 0 :(得分:0)
我对你的格式采取了一些自由,使其更容易重新创建。
这应该为您提供modalDialog
函数如何与DT
一起使用的小说。
这是一个有效的例子:
library(shiny)
library(DT)
ui <- fluidPage(
textInput('name','Protein Name'),
dataTableOutput('table1')
)
server <- function(input, output,session) {
df1 <- data.frame(A= c("BX002","BX006", "BX008"),
B= c("Actin","Tubulin", "GAPDH"),
C = c("Mouse","Human", "Human"),
D = c("WB","WB", "IHC"))
df2 <- data.frame(A= c("BX002","BX006", "BX008"),
B= c("Actin","Tubulin", "GAPDH"),
C = c("5","5", "4"),
D = c("Good","Good", "Bad"),
E = c("Kidney", "Liver", "Heart"))
tbl1 <- reactive({
if(nchar(input$name)>0){
df1[which(tolower(input$name) == tolower(df1$B)),]
}
})
output$table1 <- renderDataTable({
if(nchar(input$name)>0){
datatable(tbl1(),selection = 'single')
}
})
review_tbl <- reactive({
df2[which(df1[input$table1_rows_selected,1]==df2$A),]
})
observeEvent(input$table1_rows_selected,{
showModal(
modalDialog(
renderDataTable({
review_tbl()
})
))
})
}
# Run the application
shinyApp(ui = ui, server = server)