有一个与此有关的问题解决了。我正在使用lapply生成动态R Shiny仪表板。每个动态生成的框都需要:
以下代码完成了大部分工作。但是,我有两个主要问题:
任何帮助将是最欢迎的。
library('shiny')
library('shinydashboard')
ui <- dashboardPage( title="sample code",
dashboardHeader( title="sample code",disable=TRUE ),
dashboardSidebar(
box( width=12,title="sidebar input",solidHeader=TRUE,status="warning",background = "black",
tags$style(".skin-blue .sidebar a:link { color:orange; } a:visited {color:green;}"),
"Some text in the sidebar",
sliderInput(inputId = 'inputRatio', label='hello',
min = 0, max = 1, value = 0.5, ticks=FALSE, width = '200px'),
)
),
dashboardBody(
uiOutput("boxes")
)
)
server <- function(input, output, session) {
tableWithData <- data.frame('colA'=c(1:10), 'colB'=c(11:20), 'colC'=c(21:30) )
output$boxes <- renderUI({
lapply( 1:5, function( inputRow ) {
fluidRow(
box( width=NULL, title=paste0('Row ',inputRow), status='warning',collapsible=TRUE,collapsed=FALSE,
fluidRow(
box( width=5,
p("table output", style="font-weight:bold"),
renderTable( tableWithData[ inputRow, ] )
),
box( width=5,
radioButtons( paste0( 'row', inputRow, 'Param' ), 'Set a:' , inline=TRUE, selected = "min", c("min"="min", "max"="max", "range"="range", "none"="none")),
conditionalPanel(condition = paste0( "input.", 'row', inputRow, "Param != 'none'") ),
conditionalPanel(condition = paste0( "input.", 'row', inputRow, "Param == 'min'" ),
numericInput( paste0( 'row', inputRow,'MinLimit' ), label="Minimum", value = 0, width = "90%") ),
conditionalPanel(condition = paste0( "input.", 'row', inputRow, "Param == 'max'" ),
numericInput( paste0( 'row', inputRow,'MaxLimit' ), label="Maximum", value = 100, width = "90%") ),
conditionalPanel(condition = paste0( "input.", 'row', inputRow, "Param == 'range'" ),
numericInput( paste0( 'row', inputRow,'MinLimit' ), label="Minimum", value = 0, width = "90%"),
numericInput( paste0( 'row', inputRow,'MaxLimit' ), label="Maximum", value = 100, width = "90%") )
),
# ***** This is where I need the most help **********
box( width=4,
renderValueBox({
valueBox( input$inputRatio * eval( paste0( 'row', inputRow,'MinLimit' ) ), subtitle="i am stuck", icon = icon("list"), color = "purple" )
})
# ***************************************************
)
)
)
)
})
})
}
# Run the application
shinyApp(ui = ui, server = server)
您可以通过编程方式调用闪亮的输入,就像通过列出项目一样[[
。
eval
是邪恶的-避免它。
我想这就是你所追求的:
library('shiny')
library('shinydashboard')
ui <- dashboardPage( title="sample code",
dashboardHeader( title="sample code",disable=TRUE ),
dashboardSidebar(
box( width=12,title="sidebar input",solidHeader=TRUE,status="warning",background = "black",
tags$style(".skin-blue .sidebar a:link { color:orange; } a:visited {color:green;}"),
"Some text in the sidebar",
sliderInput(inputId = 'inputRatio', label='hello',
min = 0, max = 1, value = 0.5, ticks=FALSE, width = '200px'),
)
),
dashboardBody(
uiOutput("boxes")
)
)
server <- function(input, output, session) {
tableWithData <- data.frame('colA'=c(1:10), 'colB'=c(11:20), 'colC'=c(21:30) )
output$boxes <- renderUI({
lapply( 1:5, function( inputRow ) {
fluidRow(
box( width=NULL, title=paste0('Row ',inputRow), status='warning',collapsible=TRUE,collapsed=FALSE,
fluidRow(
box( width=5,
p("table output", style="font-weight:bold"),
renderTable( tableWithData[ inputRow, ] )
),
box( width=5,
radioButtons( paste0( 'row', inputRow, 'Param' ), 'Set a:' , inline=TRUE, selected = "min", c("min"="min", "max"="max", "range"="range", "none"="none")),
conditionalPanel(condition = sprintf( "input.row%sParam != 'none'", inputRow) ),
conditionalPanel(condition = sprintf("(input.row%sParam == 'min' || input.row%sParam == 'range')", inputRow, inputRow),
numericInput( paste0( 'row', inputRow,'MinLimit' ), label="Minimum", value = NULL, width = "90%") ),
conditionalPanel(condition = sprintf("(input.row%sParam == 'max' || input.row%sParam == 'range')", inputRow, inputRow),
numericInput( paste0( 'row', inputRow,'MaxLimit' ), label="Maximum", value = NULL, width = "90%") )
),
box( width=4,
renderValueBox({
names(input)
inputID <- paste0('row', inputRow,'MinLimit')
valueBox( input$inputRatio * input[[inputID]], subtitle="i am stuck", icon = icon("list"), color = "purple" )
})
)
)
)
)
})
})
}
# Run the application
shinyApp(ui = ui, server = server)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句