如何使用数学表达式创建 table 输出?
How to create table output with mathematical expressions?
我不知道如何创建包含像数学表达式这样的 LaTeX 的输出表。
如何在示例中显示希腊字母 rho?
library(shiny)
ui <- fluidPage(
tableOutput("table")
)
server <- function(input, output) {
output$table <- renderTable({
ts_summary <- data.frame(rho_1 = 1,
rho_2 = 2,
rho_3 = 3,
rho_4 = 4,
rho_5 = 5)
ts_summary
})
}
shinyApp(ui = ui, server = server)
你是对的。这很棘手,因为关于如何为数据框命名列的约定。这是一个可能的解决方案:
编辑:解决方案仅适用于静态表。
更新:
可以在这里找到帮助:https://github.com/rstudio/DT/issues/168
所以 afaik,它只适用于 DT::....
library(shiny)
library(DT)
ui <- fluidPage(
withMathJax(),
selectInput("number", "Number:", 1:4),
DT::dataTableOutput('table')
)
server <- function(input, output) {
proxy = dataTableProxy('table')
observe({
replaceData(proxy, df(), rownames = FALSE)
})
df <- reactive({
df = data.frame(index = 1)
df['$$\rho_1$$'] <- input$number[1]
df['$$\rho_2$$'] <- 2
df['$$\rho_3$$'] <- 3
df['$$\rho_4$$'] <- 4
df['$$\rho_5$$'] <- 5
# workaround to get rid of first column
df[ , names(df)[-1]]
})
output$table <- DT::renderDataTable(rownames = FALSE, {
isolate(df())
})
}
runApp(shinyApp(ui = ui, server = server), launch.browser = TRUE)
我不知道如何创建包含像数学表达式这样的 LaTeX 的输出表。
如何在示例中显示希腊字母 rho?
library(shiny)
ui <- fluidPage(
tableOutput("table")
)
server <- function(input, output) {
output$table <- renderTable({
ts_summary <- data.frame(rho_1 = 1,
rho_2 = 2,
rho_3 = 3,
rho_4 = 4,
rho_5 = 5)
ts_summary
})
}
shinyApp(ui = ui, server = server)
你是对的。这很棘手,因为关于如何为数据框命名列的约定。这是一个可能的解决方案:
编辑:解决方案仅适用于静态表。
更新:
可以在这里找到帮助:https://github.com/rstudio/DT/issues/168
所以 afaik,它只适用于 DT::....
library(shiny)
library(DT)
ui <- fluidPage(
withMathJax(),
selectInput("number", "Number:", 1:4),
DT::dataTableOutput('table')
)
server <- function(input, output) {
proxy = dataTableProxy('table')
observe({
replaceData(proxy, df(), rownames = FALSE)
})
df <- reactive({
df = data.frame(index = 1)
df['$$\rho_1$$'] <- input$number[1]
df['$$\rho_2$$'] <- 2
df['$$\rho_3$$'] <- 3
df['$$\rho_4$$'] <- 4
df['$$\rho_5$$'] <- 5
# workaround to get rid of first column
df[ , names(df)[-1]]
})
output$table <- DT::renderDataTable(rownames = FALSE, {
isolate(df())
})
}
runApp(shinyApp(ui = ui, server = server), launch.browser = TRUE)