Ich habe ein Shiny-Dashboard, das ich in drei Dateien getrennt habe: Haupt (Daten und Aufruf an ein generisches Dashboard), Benutzeroberfläche (Datei) und Server (server
Datei).R Shiny - Pfade von Logo und CSS-Datei, wenn ich ui und Server-Dateien teilen
Ich habe ein Logo in der Dashboard-Kopfzeile und eine CSS-Datei, daher habe ich ein www
Verzeichnis im Verzeichnis meines Codes.
Wenn ich die App mit der ui
Datei starte funktioniert es aber nicht, wenn ich die App mit der Hauptdatei starte (Präzision: Die App funktioniert, wenn ich die CSS-Codezeile kommentiere, aber das Logo wird immer noch nicht angezeigt).
Ein vereinfachtes Beispiel meines Codes ist unten.
Haupt
# Library and function
library(ggplot2)
library(shiny)
library(shinydashboard)
CountPlotFunction <- function(MyData)
{
MyPlot <- ggplot(data = MyData, aes(x = MyData)) +
geom_bar(stat = "count", aes(fill = MyData)) +
geom_text(stat = "count", aes(label = ..count..)) +
scale_x_discrete(drop = FALSE) +
scale_fill_discrete(drop = FALSE)
return(MyPlot)
}
# The data
var1 <- c("Russia","Canada","Australia","Australia","Russia","Australia","Canada","Germany","Australia","Canada","Canada")
var2 <- c("UnitedStates","France","SouthAfrica","SouthAfrica","UnitedStates","SouthAfrica","France","Norge","SouthAfrica","France","France")
var3 <- c("Brazil","Colombia","China","China","Brazil","China","Colombia","Belgium","China","Colombia","Colombia")
df <- data.frame(var1, var2, var3)
# Call the app
source(paste0(TheFileDirectory,"server.R"))
source(paste0(TheFileDirectory,"ui.R"))
shinyApp(ui = Interface, server = Serveur)
Benutzeroberfläche
# The Shiny app
Interface <- dashboardPage(skin = "black",
dashboardHeader(title = "Dashboard",
dropdownMenuOutput("messageMenu"),
tags$li(class = "dropdown",
tags$a(href = "http://google.com", tags$img(src = "Logo.png", height = "20px")))
),
dashboardSidebar(disable = TRUE),
dashboardBody(
tags$head(includeCSS("www/style.css")),
fluidPage(
selectInput(inputId = "Question",
label = "Choose the question",
choices = colnames(df),
selected = colnames(df)[1]),
mainPanel(plotOutput(outputId = "ThePlot"))
)
)
)
Server
Serveur <- function(input, output)
{
output$ThePlot <- renderPlot({CountPlotFunction(MyData = df[input$Question])})
}
Wie muss ich 'addResourcePath' hinzufügen? Ich versuche in den drei Dateien und ich habe den gleichen Fehler 'Fehler in normalizePath (directoryPath, mustWork = TRUE): path [1] =" www ": Keine solche Datei oder Verzeichnis' – Kumpelka
Versuchen Sie' setwd (TheFileDirectory) 'zuerst – HubertL
Dies wird nicht auf CSS funktionieren. Rufen Sie 'setwd (TheFileDirectory)' auf, bevor Sie ui.R bereitstellen und behalten Sie bei "www/style.css" – HubertL