我目前工作的一個閃亮的應用程序,它顯示因爲HTML代碼的大小的靜態HTML表,從另一個文件源,過濾數據的靜態HTML表。該表使用空數據表進行初始化,以便呈現空表。在HTML表格上方是正常的selectizeInput在後臺過濾數據表的字段(通過observe()函數)。然後應該使用過濾的數據表填充HTML表格。閃亮 - 填充基於輸入
我堅持在與「新」的數據表更新HTML表的過程。我試圖在觀察()中再次找到表格 - 沒有改變。我將數據表初始化爲reactiveValue,並使用reactive()函數將HTML表格封裝起來 - 再次不變。
這裏是一個玩具例子有點象我閃亮的應用程序:
app.R
library(shiny)
ui <- fluidPage(
fluidRow(
column(width = 6, uiOutput("cars"))
),
fluidRow(
column(width = 6, htmlOutput("html.table"))
)
)
server <- function(input, output) {
filtered_cars <- data.frame(matrix("NA", nrow = 1, ncol = 4, dimnames = list("NA", c("mpg","cyl","disp","hp"))))
source("server_html_table.R", local = TRUE)
output$cars <- renderUI({
selectizeInput(
inputId = "cars",
label = NULL,
choices = rownames(mtcars),
options = list(placeholder = 'Cars')
)
})
output$html.table <- renderUI({
html.table
})
observeEvent(input$cars, {
filtered_cars <- subset(mtcars, rownames(mtcars) %in% input$cars)
#some kind of update for the html table missing
})
}
# Run the application
shinyApp(ui = ui, server = server)
server_html_table.R
html.table <- tags$table(style = "border: 1px solid black; padding: 1%; width: 100%;",
tags$tr(
tags$th("Car Name"),
tags$th("MPG"),
tags$th("CYL"),
tags$th("DISP"),
tags$th("HP")
),
tags$tr(
tags$td(rownames(filtered_cars)),
tags$td(filtered_cars$mpg),
tags$td(filtered_cars$cyl),
tags$td(filtered_cars$disp),
tags$td(filtered_cars$hp)
)
)
正如你所看到的,表格單元不更新。我意識到在observeEvent中缺少某種更新函數(如updateSelectizeInput()),但我無法找到一種方法來自行編寫代碼。
我對任何形式的意見或建議表示感謝!
編輯#1:也許有關HTML表格更清晰的觀點 - 我在我的應用程序中顯示一個Profit and Loss表格,需要通過HTML手動構建。因此,我不能使用通常的dataTableOutput()和renderDataTable()函數。由於表格嚴重依賴CSS,因此使用基本HTML比htmlTable包簡單得多。