R Shiny:在函数中使用HTML(如textInput,checkboxGroupInput)

时间:2015-10-06 09:53:16

标签: html r shiny

我试图将HTML包含在闪亮的textInput()函数中。更具体地说,我想在窗口小部件中显示的文本旁边包含一个图像。以下内容写于ui.R

shinyUI(navbarPage("Page Title",theme = shinytheme("united"),
  tabPanel("Panel title",          
     sidebarLayout(
       sidebarPanel(

         textInput("textInputObject", c("Input Header", tags$span(HTML("<img src='http://www2.psd100.com/ppp/2013/10/0401/Blue-question-mark-icon-1004195336.png', title='help', alt='' />"))), value = "put text here"),

         checkboxGroupInput("checkbInp", "Checkbox Header",
                            c("Checkbox1 [?]"           = "check1"            , 
                              "Checkbox2 [?]"           = "check2"          , 
                              "Checkbox3 [?]"           = "check3")          , 
                            selected = c("check1"))
  )
)

这给了我:

enter image description here

有两个问题:

  1. 我能够将图片包含在textInput的标题中。但是,它只应显示&#34;输入标题&#34;然后是图像。如图所示,&#34; span&#34;来自tags$span的信息也会显示出来。我该如何解决这个问题?

  2. 我不知道如何将图片包含在checkboxGroupInput中。它应该取代&#34; [?]&#34; (见图)

  3. 谢谢!

2 个答案:

答案 0 :(得分:2)

#1 您可以在list来电之前使用HTML轻松解决此问题。对于#2 有点棘手,因为您可能需要自己编写整个checkbox。也许你可以像我一样宣布单独的那些,那会没关系吗?

rm(list = ls())
library(shiny)
library(shinythemes)

ui <- navbarPage("Page Title",theme = shinytheme("united"),
                 tabPanel("Panel title",          
                          sidebarLayout(
                            sidebarPanel(
                              textInput("textInputObject", 
                                        c("Input Header",list(HTML("<img src='http://www2.psd100.com/ppp/2013/10/0401/Blue-question-mark-icon-1004195336.png'/>"))), value = "put text here"),
                              checkboxInput("checkbInp",c("Checkbox1",list(HTML("<img src='http://www2.psd100.com/ppp/2013/10/0401/Blue-question-mark-icon-1004195336.png'/>"))), value = T),
                              checkboxInput("checkbInp2",c("Checkbox2",list(HTML("<img src='http://www2.psd100.com/ppp/2013/10/0401/Blue-question-mark-icon-1004195336.png'/>")))),
                              checkboxInput("checkbInp3",c("Checkbox3",list(HTML("<img src='http://www2.psd100.com/ppp/2013/10/0401/Blue-question-mark-icon-1004195336.png'/>"))))
                            ),
                          mainPanel())
                 )
)
server <- function(input, output) {}
shinyApp(ui, server)

enter image description here

答案 1 :(得分:0)

如果不需要span标记,请尝试这样:

textInput("textInputObject", c("Input Header", tags$img(src = "http://www2.psd100.com/ppp/2013/10/0401/Blue-question-mark-icon-1004195336.png", title = "help", alt = ""), value = "put text here")